2016-11-10 2 views
2

Ich habe zwei Komponenten, ComponentA verwendet ComponentB. ComponentB ist eine Tabelle, die Daten, Optionen und eine Vorlage abrufen kann, die den Tabelleninhalt definiert. Ich möchte ComponentB eine Komponente sein, um verschiedene Tabellen zu rendern. Ich habe keine Ahnung, wie man Vorlagen in Angular2 v2.1.0 rendert. Ich habe Sachen wie DynamicComponentLoader und ComponentResolver gefunden, die beide veraltet sind. Welche Komponenten bietet Angular2 2.1.0 zum Rendern von Vorlagen?Angular2 Rendervorlage

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 
} 

} }

Antwort