Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular - provided data source did not match an array, observable, or datasource

Im receiving an object in my component via @Input

@Input event

enter image description here

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

like image 277
Hugo Seleiro Avatar asked Jun 18 '19 18:06

Hugo Seleiro


1 Answers

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">
like image 145
nircraft Avatar answered Nov 15 '22 05:11

nircraft