Javascript Can';t正确插值数据-角度材料表-角度2+;
我不知道如何修改示例材料数据表,以便在其中使用我自己的数据 我的数据以以下格式显示:Javascript Can';t正确插值数据-角度材料表-角度2+;,javascript,angular,typescript,angular-material,Javascript,Angular,Typescript,Angular Material,我不知道如何修改示例材料数据表,以便在其中使用我自己的数据 我的数据以以下格式显示: export const DATA: any = { 'products': [ { 'id': 1, 'name': 'SOLID BB T-SHIRT', 'price': '28.00', ... }, ... ] 根据Material.angular.io给出的示例,其数据格式如下: export const DATA = [ {
export const DATA: any = {
'products': [
{
'id': 1,
'name': 'SOLID BB T-SHIRT',
'price': '28.00',
...
},
...
]
根据Material.angular.io给出的示例,其数据格式如下:
export const DATA = [
{
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
...
},
...
]
但是,我似乎无法使我的数据格式适合在HTML中使用的插值,因此:
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
<ng-container matColumnDef="id">
<th mat-header-cell *matHeaderCellDef> id </th>
<td mat-cell *matCellDef="let element"> {{element.id}} </td>
</ng-container>
身份证件
{{element.id}
有什么我遗漏的吗?不太清楚,因为您没有提供创建
数据源的代码,但我猜您传递的是对象,而不是数组。尝试使用数据创建数据源
。产品
当对象需要数组时,您当前正在将数据源指向该对象。因此,简单的实现可能是(in.component.ts):
dataSource=DATA[“products”]
试试这个,它对我很有用
import { MatTableDataSource } from '@angular/material';
然后将以下内容添加到ngOniInit()
ngOnInit() {
this.dataSource = new MatTableDataSource(DATA);
}
我对那张桌子一无所知。但是,也许您应该将数据作为data.products传递,以使其具有相同的类型