I have several arrays of objects in my typescript file.
I want to iterate through these arrays simultaneously and display their contents in the html file. Here is the content:
<ion-item>
{{array1[i]}} {{array2[i]}} {{array3[i]}}
</ion-item>
Luckily the arrays are always the same size. Now I want to do a for-loop after the ion-item (something like this):
<ion-item *ngFor="let i in array1">
{{array1[i]}} {{array2[i]}} {{array3[i]}}
</ion-item>
But doing it this way gives me an error: "Can't bind 'ngForIn' since it isn't a known property of 'ion-item'. Now I've found the following workaround, but it seems pretty ugly.
<ion-item *ngFor="let counter of array1; let i = index">
{{array1[i]}} {{array2[i]}} {{array3[i]}}
</ion-item>
Any advice on how to do this more efficiently / pretty would be highly appreciated :)
Thank you!
You last is the best yet, but here is an other way
TS
for(let i=0; i < n; i++){ // n is array.length
this.globalArray.push({ a1 : array1[i] , a2 : array2[i] , a3 : array3[i] });
}
HTML
<ion-item *ngFor="let item of globalArray;">
{{item.a1}} {{item.a1}} {{item.a1}}
</ion-item>
This is pretty simple
<ul>
<li *ngFor="let item of array1">{{item.property}}<li>
<ul>
<ul>
<li *ngFor="let item of array2">{{item.property}}<li>
<ul>
<ul>
<li *ngFor="let item of array3">{{item.property}}<li>
<ul>
来源:https://stackoverflow.com/questions/45894387/html-ionic-3-x-how-to-use-a-for-loop-in-the-html-file-using-in-instead-of-of