0

I'm having a problem where I am loading dynamic table headers from a server. However, when they load, instead of displaying across the table like they should they stack up in one column.

Here is the html:

                 <tr *ngFor="let title of headers">
                 <th class='table-header'>{{title['COLUMN_NAME']}}</th>
             </tr>
             </thead>
             <tbody >
                 <tr *ngFor="let item of data | paginate : {itemsPerPage: 25, currentPage: p} ">
                     <td>{{item.ID}}</td>
                     <td>{{item['78d00422ce41_POWER']}}</td>
                     <td>{{item['78d00422ce41_TIME']}}</td>
                     <td>{{item['78d00422821c_POWER']}}</td>
                     <td>{{item['78d00422821c_TIME']}}</td>


             </tr>
             </tbody>

heres what the 'headers' array looks like:

[  
   {  
      "COLUMN_NAME":"ID"
   },
   {  
      "COLUMN_NAME":"78d00422ce41_POWER"
   },
   {  
      "COLUMN_NAME":"78d00422ce41_TIME"
   },
   {  
      "COLUMN_NAME":"78d00422821c_POWER"
   },
   {  
      "COLUMN_NAME":"78d00422821c_TIME"
   }
]

If there's something I'm missing, or that I did wrong, please let me know!

4
  • whats array headers? Commented May 26, 2018 at 7:02
  • stackblitz Please !!! Commented May 26, 2018 at 7:04
  • @fatemefazli ill add that to the question Commented May 26, 2018 at 7:09
  • 1
    <thead> <tr *ngFor="let title of headers"> <th class='table-header'>{{title['COLUMN_NAME']}}</th> </tr> </thead> works fine for me. Commented May 26, 2018 at 7:14

1 Answer 1

4

Use *ngFor inside <th> tag

<th *ngFor="let title of headers" class='table-header'>{{title['COLUMN_NAME']}}</th>

Hope this will work for you! :)

Sign up to request clarification or add additional context in comments.

2 Comments

Worked like a charm! Can't believe I didn't think of this first lol
Cheers! glad to here that :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.