Angular Material - mat-table not rendering data from rest api
You need to create new MatTableDataSource()
and then on data receiving pass that data to dataSource.data
array.
ngOnInit() {
// this.dataSource = new MatTableDataSource(this.getLaps());
this.dataSource = new MatTableDataSource(); // create new object
this.getLaps(); // forgeted this line
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
getLaps() {
this.rest.getLaps().subscribe((data: {}) => {
console.log(data);
console.log('Laps');
this.dataSource.data = data; // on data receive populate dataSource.data array
return data;
});
}