Pau*_*aul 5 angular-material angular angular5
在 *ngFor 循环中将数据源从数组传递到 mat-table 的方法是什么。即我使用 *ngFor 创建多个表,每个表都需要一个数据源,但是当我尝试以下操作时它不起作用:
<mat-table #table [dataSource]="dataSources[i]">
Run Code Online (Sandbox Code Playgroud)
而 'i' 是在 html 模板中预先定义的:
<mat-expansion-panel *ngFor="let customer of customers; let i = index">
Run Code Online (Sandbox Code Playgroud)
更新:
以下对我有用,我将 dataSource 添加到每个客户对象,而不是将其分开并尝试通过“i”索引访问
<mat-table #table [dataSource]="customer.dataSource">
Run Code Online (Sandbox Code Playgroud)
试试这个代码:
<mat-table *ngFor="let dataSource of dataSources" #table [dataSource]="dataSource">
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你 :)
| 归档时间: |
|
| 查看次数: |
4580 次 |
| 最近记录: |