Answer the question
In order to leave comments, you need to log in
Dynamic ngFor tags in Angualar2?
Faced a problem, there is an array that contains objects:
this.dataCell = [
{"id": "1", "fill": "#D9D9D9", "type": "path", "d": "L111.2,484.7"},
{"id": "2", "fill": "#FF0000", "type": "polyline", "points": "L327,53.1"},
{"id": "3", "fill": "#772BA9", "type": "polyline", "points": "407 140"},
{"id": "4", "fill": "#D9D9D9", "type": "path", "d": "L478.4,97.3"},
{"id": "5", "fill": "#772BA9", "type": "path", "d": "L576.9,181.1"}
];
<path *ngFor="let item of dataCell">{{item.type}} fill="{{item.fill}} id="{{item.id}}</path>
<app-for-example *ngFor="let item of dataCell" [dataCell]="dataCell">
<{{item.type}} [fill]="{{item.fill}}"></{{item.type}}>
</app-for-example>
Answer the question
In order to leave comments, you need to log in
It must be something...
<app-for-example *ngFor="let item of dataCell" [dataCell]="dataCell" [ngSwitch]="item. type">
<path *ngSwitchCase ="item.type == 'path'" attr.fill="{{item.fill}} attr.id="{{item.id}}></path>
<polyline *ngSwitchCase ="item.type == 'polyline'" attr.fill="{{item.fill}} attr.id="{{item.id}}></polyline>
</app-for-example>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question