Hy, I'm working on a web-based application in angular 5. In this app, we use the angular material. On one of the pages we have a mat-table but we can't get it to work. The table never shows us any data. The data we call from multiple backends and with a debugger, we know the data isn't null. Even if we try to use the angular material example it still doesn't work. What do we wrong?
HTML
<mat-table #invoiceTable [dataSource]="datasource" matSort>
<ng-container matColumnDef="SerialNr">
<th mat-header-cell *matHeaderCellDef> SerialNr. </th>
<td mat-cell *matCellDef="let movement" > {{movement?.serialNr}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;">
</tr>
</mat-table>
TS
displayedColumns = ['SerialNr'];
movements = [];
// datasource = new MatTableDataSource<Movement>(this.movements);
datasource: MovementDataSource;
getMovementsByVehicleID() {
this.authUser.ownedVehicles.forEach((vehicle) => {
this.movementService.getMovementsByCarID(vehicle.id).subscribe(
(newMovemnts) => {
this.movements = newMovemnts;
this.datasource.update(newMovemnts);
},
);
}
);
}
export class MovementDataSource extends DataSource<Movement> {
constructor(private movements: Movement[]) {
super();
}
connect(): Observable<Movement[]> {
return Observable.of(this.movements);
}
update(movements: Movement[]) {
movements.forEach((move) => {
this.movements.push(move);
});
}
disconnect(collectionViewer: CollectionViewer): void {
}
}
MATERIAL.TS
@NgModule({
imports: [
MatButtonModule,
MatToolbarModule,
MatGridListModule,
MatIconModule,
MatInputModule,
MatMenuModule,
MatPaginatorModule,
MatSidenavModule,
MatSnackBarModule,
MatCardModule,
MatTableModule,
MatSortModule,
MatProgressSpinnerModule,
CdkTableModule,
],
exports: [
MatButtonModule,
MatToolbarModule,
MatGridListModule,
MatIconModule,
MatInputModule,
MatMenuModule,
MatPaginatorModule,
MatSidenavModule,
MatSnackBarModule,
MatCardModule,
MatTableModule,
MatSortModule,
MatProgressSpinnerModule,
CdkTableModule
],
declarations: []
})
export class MaterialModule {
}
We have tried a lot of things. this is the latest version but it still doesn't work. Off course we added the material module in the imports of the app.module.ts. The strange thing is even the examples doesn't work. Any idea's?
I have updated my question. It still isn't working