1

I have some data that contains the selector of a component:

{
  label: 'This is a label',
  componentSelector: '<app-mycomponent></app-mycomponent>'
}

In my app.component.html

Instead of doing this (for example):

<div>
  <app-mycomponent></app-mycomponent>
</div>

I would like to do this:

{{data.componentSelector}}

At the moment when I try this it's returning a string instead of replacing it with the contents of the component.

How can I do this?

2
  • Can you try <div [innerHtml]="data.componentSelector"></div>? Commented Nov 29, 2017 at 18:54
  • No, is just displayed as a string too Commented Nov 29, 2017 at 19:01

1 Answer 1

1

You cannot interpolate a component, because it is made up of typescript, html, and css. it has to compile to be displayed, if you think about it, it makes sense.

On another note, even if you could interpolate, it would be a poor Angular Pattern, and could have unexpected outcomes especially in production. Stick to the best practices.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.