简体   繁体   中英

Angular2 Looping through dynamic columns

I'm building a dynamic table using angular2 using *ngFor as below, but I'm not able to see data. I'm not sure {{x[col]}} is correct, any idea?

<tr *ngFor="let x of exportList">
     <td *ngFor="let col of cols">
        {{x[col]}}
     </td>                      
 </tr>

You need to traverse each row in the inner loop. Try:

<tr *ngFor="let rows of exportList">
     <td *ngFor="let col of rows">
        {{col}}
     </td>                      
 </tr>
<tr *ngFor="let x of exportList">
     <td *ngFor="let col of x">
        {{col}}
     </td>                      
 </tr>

you simply need to replace cols with x. exportList contains numbers of object.so in x you will get one object in each loop.By using object,you can fetch each field.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM