Issue
I have a multidimensional array in angular
html
<table>
<tr *ngFor="let x of multi">
<td>{{x}}</td>
<td>{{x}}</td>
<td>{{x}}</td>
</tr>
</table>
ts edit* - you dont need the for i use
basically you only need to declare the array
( multi:Number[][] = [[1,2,3],[21,22,23], [31,32,33]]; )
multi:Number[][] = [[1,2,3],[21,22,23], [31,32,33]];
ngOnInit(): void {
for (let i = 0; i < 3; i++) {
for (let j = 0; j < 3; j++) {
this.multi[[i][j]];
console.log(this.multi[i][j]);
}
}
}
well my outcome isn´t exatly want i wanted
1,2,3 1,2,3 1,2,3
21,22,23 21,22,23 21,22,23
31,32,33 31,32,33 31,32,33
this is want i was trying to get
1 2 3
21 22 23
31 32 33
thx for help
Solution
You're not iterating over the second dimension. Try this:
<table>
<tr *ngFor="let y of multi">
<td *ngFor="let x of y">{{x}}</td>
</tr>
</table>
Answered By - Guerric P
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.