Search code examples
arraysangularclassarrayofarrays

Array of Arrays in Angular Class


I'm new to Angular and cant really grasp how to loop through an array inside an array.

I'm trying to achieve same thing as the following C code:

   for (int i = 0; i < 10; i ++){
       printf ("%d", ar[i]);

       for (int j =0; j < 3; j ++ )
       {
           printf ("%d", arre[j]);
       }
       printf ("\n");
   }

But in my case I have a class:

class Arende{
    Id:number 
    Namn :string 
    Status :string 
    RegistreringLista :Registrering[]
}

HTML:

    <tr *ngFor="let arende of arenden">
      <td> {{arende.Id}} </td>
      <td> {{arende.Namn}}</td>
      <td> {{arende.RegistreringLista.xxxx}}</td>
      <td> {{arende.RegistreringLista.yyyy}}</td> 
      <td> {{arende.ResitreringsLista.zzzzz}}</td> 

I thought that there should be some way to do a:

<tr *ngFor="let arende of RegistreingsLista">

But that dosen't seem right either ... I have trouble understanding the loop sequence ... How should I set it up?


Solution

  • So this is how I solved the problem:

       <ng-container *ngFor="let arende of arenden">
        <tr *ngFor ="let item of arende.RegistreringLista">
          <td> {{arende.Id}} </td>
          <td> {{arende.Namn}}</td>
          <td> {{item.XXXX}}</td>
          <td> {{item.YYYY}}</td>
          <td> {{item.ZZZZ}}</td>  
    

    I used "Ng-container" not to screw with the HTML.