I think each table is being populated the size of the test array. Is there a way to only populate each table once on the correct table index?
In the .ts file I have headers and my 2D string array
headers = ['Header1', 'Header2']
test = [['Test1', 'Test2'], ['Test3', 'Test4', 'Test5']]
My HTML looks like this
<ng-container *ngFor="let h of headers; let i = index"
<h2>{{ h }}</h2>
<p-table>
<ng-template p template="body">
<ng-container *ngFor="let rows of test[i]; let j = index">
<label>{{rows}}</label>
</ng-container>
</ng-template>
</p-table>
</ng-container>
When I do this my table looks like this:
Header1
Table1 |
---|
Test1 |
Test2 |
Test1 |
Test2 |
Header2
Table2 |
---|
Test3 |
Test4 |
Test5 |
Test3 |
Test4 |
Test5 |
when I want it to display like this:
Table1 |
---|
Test1 |
Test2 |
Table2 |
---|
Test3 |
Test4 |
Test5 |
2
Answers
I guess you are using loop in a wrong way, Can yu please use this way.
Since you are using PrimeNG tables, you need to use their syntax:
StackBlitz here