I have an Angular 2 component which renders a nice table with kitten object data.
Since some of the columns are going to be reused in a different component, I'm looking for a way to extract the <td>
into a separate component (dynamic-kitten-tds
). I can not move <td>
s which render kitten.name
and kitten.lastWashed
since they are unique to cat-o-base
component:
cat-o-base.component.html
<table>
<tbody>
<tr *ngFor="let kitten of kittenBasket">
<td>{{ kitten.name }}</td>
<dynamic-kitten-tds [value]="kitten"></dynamic-kitten-tds>
<td>{{ kitten.lastWashed | date }}</td>
</tr>
</tbody>
<table>
dynamic-kitten-tds.component.html
The entire template of the dynamic-kitten-tds
component looks like this:
<td *ngFor="let preference of kitten.preferences">{{ preference | json }}</td>
Limitation 1
I may not use the *ngFor
like this:
<td>{{ kitten.name }}</td>
<td *ngFor="let preference of kitten.preferences" [value]="preference"></td>
<td>{{ kitten.lastWashed | date }}</td>
This limitation comes from the business logic that must be implemented as a part of dynamic-kitten-tds
component.
Limitation 2
The code must result in a valid DOM emission.
Question
How do I achieve it? Using auxiliary components is fine. Using special structural directives is fine too.
P.S
I looked through some other SO questions (like this one) however didn't find quite matching problem definition.