Я пытаюсь использовать Angular MatTable с асинхронным каналом. Я получаю данные из RESTAPI как Observable. Однако, когда я использую ([dataSource] = dataSource | async) таким образом, я получаю ошибку, о которой я упоминал выше.
репозиторий.service.ts:
public GetList(controller: string): Observable<T[]> {
return this.httpclient.get<T[]>(this.apiURL + '/' + controller + '/getList', { headers: this.headers });}
контакт.component.ts:
ngOnInit() {
this.contactService.GetList("OfferContact").subscribe(res => {
this.ContactList = res
this.setFunctions(this.ContactList)
})}
setFunctions(list) {
this.dataSource.data = list;
this.spinner.hide()
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
contact.component.html:
<table mat-table [dataSource]="dataSource|async" matSort>
<ng-container matColumnDef="company">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Firma Adı </th>
<td mat-cell *matCellDef="let element"> {{element.company}} </td>
</ng-container>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Yetkili Adı </th>
<td mat-cell *matCellDef="let element"> {{element.name}} </td>
</ng-container>
...
</table>
<mat-paginator [pageSizeOptions]="[20, 30, 50, 70, 100]"></mat-paginator>
Ошибка
ERROR Error: InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'
это скриншот. Как вы можете видеть в правом нижнем углу, данные извлекаются, но не обрабатываются в таблице.
Кто-нибудь может помочь с этой проблемой?