Angular2, evaluate template from string inside a component

Viewed 11413

It's possible evaluate template from string in a variable?. I need place the string in the component instead of the expression, e.g.

template: "<div>{{ template_string }}</div>"

template_string contains: <b>{{ name }}</b>

and all should be evaluated to <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 content of the variable on current context.

It's possible? I need something to use this approach because template_string can be changed when the component is used.

Edit1:

Angular Version: 4.0.3

E.g.

@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>`;
}

Usage:

<product-item [name]="product.name" [price]="product.price"></product-item>

Expected: Product Name USD3.00

Output: {{ name }} <b>{{ price | currency }}</b>

3 Answers
Related