I have successfully implemented a table using MatTableModule
in Angular with Typescript
.
Everything works perfectly when I assign values to the datasource
like this:
let dataRow = {name: dealerInfo.name, address: dealerInfo.address, town: dealerInfo.town, contact: dealerInfo.contact};
this.dataSource = [dataRow];
However, when attempting to add rows dynamically by using push()
, it doesn't work and the data is not displayed in the HTML. Here's what I tried:
let dataRow = {name: dealerInfo.name, address: dealerInfo.address, town: dealerInfo.town, contact: dealerInfo.contact};
this.dataSource.push(dataRow);
This is how my data source is currently defined:
dataSource: any [] = [];
What is the correct way to add elements dynamically to the data source?