I'm encountering an issue with the Angular Material Table (Angular Material Table)
After using
ng generate @angular/material:material-table --name=car-table
to create the default angular table, everything works fine.
However, when I attempt to inject data (cars) into the CarsTableDataSource
, it stops functioning properly. It seems to be related to async functions and the ngOnInit
lifecycle hooks.
You can find the code on StackBlitz. The crucial section is in the src/app/cars/
folder.
cars.component.ts
// insert different code here
cars-table-datasource.ts
// insert different code here
cars.component.html
// insert different code here
The problem stems from the ngOnInit
and:
// insert different code here
An error occurs with
ERROR TypeError: Cannot read property 'cars' of undefined
, indicating that dataSource
is undefined during template parsing, even though the ngOnInit
:
// insert different code here
If you need additional information, feel free to ask.