core icon indicating copy to clipboard operation
core copied to clipboard

ngFor append index to key

Open 9thstudio opened this issue 4 years ago • 3 comments

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}]

9thstudio avatar Apr 16 '20 15:04 9thstudio

<ion-label>{{ industries[i]?.name  | translate}}</ion-label>

try something like this

igorpetuh avatar Apr 24 '20 10:04 igorpetuh

Thanks will try it but I ended up in adding name in separate array and use that for ngFor.

9thstudio avatar Apr 24 '20 13:04 9thstudio

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>

se1ya avatar Apr 10 '24 20:04 se1ya