Is it possible to evaluate a pattern from a string in a variable ?. I need to put a string in a component instead of an expression like
template: "<div>{{ template_string }}</div>"
template_string contains: <b>{{ name }}</b>
and everything should be appreciated in <div><b>My Name</b></div>
but i see <div>{{ template_string }}</div>
I need something like {{ template_string | eval }}or something else to evaluate the contents of a variable in the current context.
Is it possible? I need to use something, because it template_stringcan be changed when using the component.
Edit1:
Angular Version: 4.0.3
eg.
@Component({
selector: 'product-item',
template: `
<div class="product">{{ template }}</div>`,
})
export class ProductItemComponent {
@Input() name: string;
@Input() price: number = 0;
@Input() template: string = `{{ name }} <b>{{ price | currency }}</b>`;
}
Using:
<product-item [name]="product.name" [price]="product.price"></product-item>
Expected: Product Name USD3.00
Conclusion: {{ name }} <b>{{ price | currency }}</b>
source
share