У меня есть два компонента, ComponentA использует ComponentB. ComponentB - это таблица, которая может извлекать данные, параметры и шаблон, который определяет содержимое таблицы. Я хочу, чтобы ComponentB был компонентом для визуализации разных таблиц. Я не знаю, как отображать шаблоны в Angular2 v2.1.0. Я нашел такие вещи, как DynamicComponentLoader и ComponentResolver, которые оба устарели. Какие компоненты предоставляет Angular2 2.1.0 для визуализации шаблонов?Angular2 render template
Componenta:
@Component({
'template':<my-table [template]="template" [options]="options" [data]="data"></mytable>
)}
export class ViewA{
template:string;
ngOnInit(){
this.template = `
<tr
*ngFor="let item of items">
<td>{{item.name}}</td>
</tr>
`
}
}
ComponentB:
@Component({
selector: 'my-table',
'template':`
<table>
<thead>
<th *ngFor="let conf of config.columns">
{{conf.title}}
</th>
</thead>
<tbody #tBody>
</tbody>
</table>
`
)}
export class ViewB{
@Input('template') template:string;
@Input('data') data:MyData;
@Input('options') options:MyOptions;
constructor(){
//todo: create template element, append template element into the tbody element
}
}}