Home > Software design >  How to use *ngFor parent index as a parameter in a nested *ngfor
How to use *ngFor parent index as a parameter in a nested *ngfor

Time:04-22

Im trying to pass my parent index to a nested ngFor so i can access an array: "name1, name2, etc"

<ion-item *ngFor="let b of banca ; let i = index">
   <ion-select>
       <ion-select-option *ngFor="let n of name   [i 1]" [value]="n">{{n}}</ion-select-option>
   </ion-select>
</ion-item>

Error:

Cannot find a differ supporting object 'undefined1' of type 'string'. NgFor only supports binding to Iterables such as Arrays.

I´ve tried different combinations but i can't figure it out. How is the correct syntax to pass the value?

Thanks!

CodePudding user response:

Although the question is not entirely clear what you are trying to do could never work.In your example name0 is the list,then name1 and name2, etc. The error says "Undefined1" is not an array because not even name exists. If what you want to do is iterate an array inside the initial array you can do

  <ion-item *ngFor="let b of banca ; let i = index">
   <ion-select>
      <ion-select-option *ngFor="let n of b.name[i]" [value]="n.attribute"></ion-select-option>
   </ion-select>
</ion-item>

where attribute is anything you got in that array

  • Related