【发布时间】:2019-04-11 14:05:55
【问题描述】:
我正在使用角度材料表来显示我的 dataSource,它实际上是一个 Observable,但它不起作用。我试着把它展示在桌子外面,它工作得很好。我也尝试使用changeDetectorRefs.detectChanges()。这是我的代码和渲染的组件。
component.ts:
ngOnInit() {
this.getCustomers();
this.changeDetectorRefs.detectChanges();
}
getCustomers(): void {
this.purchaseService.getCustomersInfo()
.subscribe(customers => {
this.options = customers;
this.dataSource=customers;
});
}
displayedColumns = ['id'];
component.html:
<div *ngFor="let element of dataSource">
{{element.id}}
</div>
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
<!-- Position Column -->
<ng-container matColumnDef="id">
<th mat-header-cell *matHeaderCellDef> Customer Id </th>
<td mat-cell *matCellDef="let element"> {{element.id}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
渲染组件:
【问题讨论】:
-
控制台中的任何错误
-
@SachilaRanawaka 没有错误:/
标签: angular angular-material observable