7

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

2
  • 4
    try using [dataSource]= "event.expenses" Commented Jun 18, 2019 at 18:05
  • @nircraft Thank you !!! Work Commented Jun 18, 2019 at 18:11

1 Answer 1

16

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">
Sign up to request clarification or add additional context in comments.

1 Comment

@HugoSeleiro, Thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.