Im receiving an object in my component via @Input
@Input event
now I need to use the expenses array on my angular material table.
<div class="table-container" *ngIf="event">
<table mat-table [dataSource]="event" class="mat-elevation-z8">
<ng-container matColumnDef="type">
<th mat-header-cell *matHeaderCellDef> No. </th>
<td mat-cell *matCellDef="let element"> {{event.type}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
</div>
But im getting the error:
provided data source did not match an array, observable, or datasource
The dataSource
supplied to the mat-table
is not an array because of which you see that error.
The simplest way to provide data to the mat-table
is by passing a data array to the table's dataSource
input.
Since your expenses
array is in the event object, You need to pass event.expenses
to table as dataSource
.
<table mat-table [dataSource]="event.expenses" class="mat-elevation-z8">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With