Im having issues with the mat-table not loading any new data after it has been initially created. I have changed from a regular html table using a ngFor to generate the rows which was working fine with the same data source. This is the mat-table html I am using:
<table mat-table [dataSource]="stocks" multiTemplateDataRows class="mat-elevation-z8">
<ng-container matColumnDef="symbol">
<th mat-header-cell *matHeaderCellDef> Symbol </th>
<td mat-cell *matCellDef="let stock"> {{stock.symbol}} </td>
</ng-container>
<ng-container matColumnDef="price">
<th mat-header-cell *matHeaderCellDef> Price </th>
<td mat-cell *matCellDef="let stock"> {{stock.price}} </td>
</ng-container>
<ng-container matColumnDef="change">
<th mat-header-cell *matHeaderCellDef> Change </th>
<td mat-cell *matCellDef="let stock"> {{stock.change}} </td>
</ng-container>
<ng-container matColumnDef="changePercent">
<th mat-header-cell *matHeaderCellDef> % Change </th>
<td mat-cell *matCellDef="let stock"> {{stock.changePercent}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="columns"></tr>
<tr mat-row *matRowDef="let row; columns:columns;" class="example-detail-row"></tr>
</table>
This is the regular HTML table that worked:
<table>
<tr>
<th>Symbol</th>
<th>Price</th>
<th>Change</th>
<th>% Change</th>
</tr>
<tr *ngFor="let stock of stocks | async" class="stock">
<td>{{ stock.symbol }}</td>
<td>{{ stock.price }} {{ stock.currency }}</td>
<td>{{ stock.change }}</td>
<td>{{ stock.changePercent }}</td>
</tr>
</table>
The variable stocks is of type Observable. Any suggestions as to why the table no longer updates when the value of "stock" changes?
Edit: Stocks is set using this:
constructor(private storageService: StorageService){
this.stocks = this.storageService.getAllStocks();
}
The getAllStocks() function makes several requests to an api and then returns them as a Observable
Edit2:
getAllStocks(): Observable<any[]> {
return of(this.allStocks);
}
where allStocks is a list of stocks within a service