Ich habe eine Komponente für die Tabelle. Ich habe Array- und Komponenten-Render-Tabelle hinzugefügt. Hier ist mein Code:Angular2 benutzerdefinierte Komponente - Vorlage
<my-table [source]="data">
<my-column [name]="Id" [title]="Object id">
<my-column [name]="Description" [title]="Object Description">
</my-table>
Komponente:
<table>
<tr ngFor="let row of source">
<td *ngFor="let column of columns">{{row[column.value]}}</td>
</tr>
</table>
Diese Komponente erstellen Tabelle (Attribut Name ist Eigenschaft für "Bindung" von der Quelle). Ich möchte Daten in Spalten formatieren. Ich habe versucht, den Einsatz <ng-content>
:
Komponente:
<table>
<tr ngFor="let row of source">
<td *ngFor="let column of columns"><ng-content select="[columnBody] "></ng-content></td>
</tr>
</table>
Verwendung:
<my-table [source]="data">
<my-column [name]="Id" [title]="Object id">
<my-column [name]="Description" [title]="Object Description">
<div columnBody>HOW TO USE VALUE (row[column.value]) HERE??</div>
</my-column>
</my-table>
I Gebrauchswert benötigen, die in Objekt in component.html ist, wo ich diese Komponente verwenden. Es ist möglich?
kurzes Beispiel: Komponente:
<ng-content select="[columnBody]" value="row[column.value]">
Verwendung:
<div columnBody><strong>{{value}}</strong></div>
Sie können diese Frage als eine Idee https://stackoverflow.com/questions/42586743/adding-a-link-template-column-to-a-custom-table-component betrachten – yurzui