core
core copied to clipboard
ngFor append index to key
I am trying to get the translation from array with ngFor but its will not getting the value till I can set the index with key. How can I append index to key which is array in language json
<ion-item *ngFor="let ind of checkboxformArray.controls; let i = index">
<ion-label>{{ 'industries'+[i].name | translate}}</ion-label>
<ion-checkbox [formControl]="ind" >
</ion-checkbox>
</ion-item>
It print like this and not the real names of industries which is set in json industries0. industries1 industries2
json: "industries" : [{"name": "ABC}, {"name": "XYZ}, {"name": "MNO}]
<ion-label>{{ industries[i]?.name | translate}}</ion-label>
try something like this
Thanks will try it but I ended up in adding name in separate array and use that for ngFor.
I got the same issue.
Solution is to add the number like this:
<ion-label>{{ "industries." +i +".name" | translate}}</ion-label>
or
<ion-label>{{ "industries.0.name" | translate}}</ion-label>