2016-11-10 7 views
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 
} 

}}

答えて

2

私はこの非常に話題にロブWormaldによってこのビデオを見ました。その少し長いですが、これを自分で行う方法を見てみましょう。

https://www.youtube.com/watch?v=ZqGvilzDbac

関連する問題