So basically I have an interface defined in Angular that looks something like this:
export interface product {
brand: String,
type: String,
value: number,
fields: Rating[]
}
the fields property is an array of Rating objects, the point being that the user can add numerous Ratings to the field property. The problem is that I can't work out how to essentially flatten this object onto the table so that all the fields just appear as another column.
brand type value field1 field2 field3
row1
row2
At the moment I have the html template iterating through the product object, although when you hit fields it does as you'd think and gives you a column of [Object object], [Object object]. Is there a way I could maybe have another nested loop inside my current loop... Or something along those lines. Current table code looks like this.
<mat-table [dataSource]="data">
<ng-container *ngFor="let col of columns" matColumnDef="{{col}}">
<mat-header-cell *matHeaderCellDef>{{ col }}</mat-header-cell>
<mat-cell *matCellDef="let element">
{{ element[col] }}
</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="columns"></mat-header-row>
<mat-row *matRowDef="let row; columns: columns;"></mat-row>
</mat-table>
Any help would be greatly appreciated.