As expected, in Angular 2 I can create components and if I use them inside a template, they will render. In this code, "text" is the selector on another component and it works as expected if I pass some string into [value]:
@Component({
selector: 'my-app',
template: `
<div class="main">
<text [value]="testModel.data.value"></text>
</div>
`
})
export class AppComponent {
name = 'Angular Example';
testModel = {
data: {
value: `Regular string text works fine.`
}
}
}
But what I need is to pass string html data into a component and that data can also contain an angular component, something more like this:
@Component({
selector: 'my-app',
template: `
<div class="main">
<text [value]="testModel.data.value"></text>
</div>
`
})
export class AppComponent {
name = 'Angular Example';
testModel = {
data: {
value: `<b>Some</b>
text value to
<inner-component>
this component gets ignored when text is rendered
</inner-component>
render
`
}
}
}
I have seen other answers for dynamically generating components, but I don't need that, just static pre-defined components that I have already created that might exist inside my data strings.
Here is the text component:
import { Component, Input, ViewChild } from '@angular/core';
@Component({
selector: 'text',
template: `
<div >
<div [innerHtml]="value">loading...</div>
</div>
`
})
export class TextComponent {
@Input() value: string;
}
Ideally the string I pass in would have any html rendered as well as any Angular rendered. Here is what I mean in angular 1: https://plnkr.co/edit/FacA3AwOqJA2QARK28c8?p=preview
Edit: Not A Duplicate
I don't see how this plunk is an answer: http://plnkr.co/edit/wh4VJG?p=preview