Home > Enterprise >  multidimensional array in angular with *ngFor
multidimensional array in angular with *ngFor

Time:05-31

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

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

CodePudding user response:

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>
  • Related