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: \"
not sure how you're building the template string
import { ..., OnInit } from '@angular/core';
@Component({
selector: 'product-item',
template: `
`,
})
export class ProductItemComponent implements OnInit {
@Input() name: string;
@Input() price: number = 0;
@Input() pre: string;
@Input() mid: string;
@Input() post: string;
template_string;
ngOnInit() {
// this is probably what you want
this.template_string = `${this.pre}${this.name}${this.mid}${this.price}${this.post}`
}
}
the string can be built from outside the component, would still recommend something like ngIf to control dynamic templates though.