我通过@Input 在我的组件中接收一个对象
@输入事件
现在我需要在我的 Angular Material 表上使用费用数组。
<div class="table-container" *ngIf="event">
<table mat-table [dataSource]="event" class="mat-elevation-z8">
<ng-container matColumnDef="type">
<th mat-header-cell *matHeaderCellDef> No. </th>
<td mat-cell *matCellDef="let element"> {{event.type}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
</div>
但我收到错误:
provided data source did not match an array, observable, or datasource
最佳答案
dataSource
提供给mat-table
不是数组,因此您会看到该错误。
向 mat-table
提供数据的最简单方法是通过将数据数组传递给表的 dataSource
输入。
由于您的 expenses
数组在事件对象中,您需要通过 event.expenses
表为 dataSource
.
<table mat-table [dataSource]="event.expenses" class="mat-elevation-z8">
关于Angular - 提供的数据源与数组、可观察对象或数据源不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56654682/