I am trying to use Angular MatTable with an async pipe. I get the data from RESTAPI as Observable. However, when I use ([dataSource] = "dataSource | async") in this way, I get the error I mentioned above.
repository.service.ts:
public GetList(controller: string): Observable<T[]> {
return this.httpclient.get<T[]>(this.apiURL + '/' + controller + '/getList', { headers: this.headers });}
contact.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>
the error
ERROR Error: InvalidPipeArgument: '[object Object]' for pipe 'AsyncPipe'
this is the screenshot. As you can see at the bottom right, the data is fetched but not processed into the table.
Can anyone help with this issue?