首页 文章

UAngular 5:* ngFor循环中的mat-table [dataSource],如何从数组传递数据源

提问于
浏览
2

将数据源从数组传递到* ngFor循环中的mat-table的方法是什么?即我使用* ngFor创建多个表,每个表都需要一个数据源,但是当我尝试以下操作时它不起作用:

<mat-table #table [dataSource]="dataSources[i]">

而'i'是在html模板中定义的:

<mat-expansion-panel *ngFor="let customer of customers; let i = index">

Update:

以下对我有用,我将dataSource添加到每个客户对象,而不是将其分开并尝试通过'i'索引进行访问

<mat-table #table [dataSource]="customer.dataSource">

1 回答

  • 1

    试试这段代码:

    <mat-table *ngFor="let dataSource of dataSources" #table [dataSource]="dataSource">
    

    希望能帮助到你 :)

相关问题