Вам необходимо преобразовать JSON
в переменную типа
const jsonData = {
"products": {
"items":[
{
"productId": "1",
"dept": "home",
"itemtype": "small"
},
{
"productId": "2",
"dept": "kitchen",
"itemtype": "medium"
}
]
}
}
Затем datasource
необходимо объявить с массивом items
как,
dataSource = jsonData.products.items;
И столбцы sisplay с такими свойствами, как
displayedColumns = ['productId', 'dept', 'itemtype'];
и HTML
шаблон, ссылающийся на эти свойства,
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
<ng-container matColumnDef="productId">
<th mat-header-cell *matHeaderCellDef> ID </th>
<td mat-cell *matCellDef="let element"> {{element.productId}} </td>
</ng-container>
<ng-container matColumnDef="dept">
<th mat-header-cell *matHeaderCellDef> department </th>
<td mat-cell *matCellDef="let element"> {{element.dept}} </td>
</ng-container>
<ng-container matColumnDef="itemtype">
<th mat-header-cell *matHeaderCellDef> Item type </th>
<td mat-cell *matCellDef="let element"> {{element.itemtype}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
Рабочий материал таблицы Stackblitz