2
私は2つのコンポーネントを持っていますが、ComponentAはComponentBを使用しています。 ComponentBは、データ、オプション、およびテーブルの内容を定義するテンプレートを取得できるテーブルです。 私は、ComponentBを異なるテーブルをレンダリングするコンポーネントにします。 Angular2 v2.1.0でテンプレートをレンダリングする方法がわかりません。 DynamicComponentLoaderやComponentResolverのようなものは、どちらも時代遅れです。 Angular2 2.1.0はテンプレートをレンダリングするためにどのコンポーネントを提供しますか?Angular2レンダリングテンプレート
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
}
}}