Objective: Create a dynamic table using JSON data
<mat-table class="mat-elevation-z8" *ngIf="carrierRates" [dataSource]="carrierRates">
<ng-container *ngFor="let columnName of columnsList" matColumnDef="{{columnName}}">
<mat-header-cell *matHeaderCellDef>{{columnName}}</mat-header-cell>
<mat-cell *matCellDef="let itemRate">
{{itemRate.$columnName}}
</mat-cell>
<mat-footer-cell *matFooterCellDef></mat-footer-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="columnsList;"></mat-header-row>
<mat-row *matRowDef="let row; columns: columnsList;"></mat-row>
<mat-footer-row *matFooterRowDef="columnsList"></mat-footer-row>
</mat-table>
Inquiry 1: How can I iterate through the column list and data source in separate loops?
Inquiry 2:
What is the correct method to pass the value of columnName in this line
{{itemRate.$columnName}}
Note: columnName represents the keys in the JSON object
{"planId":"abcd",
"rateAreaId":"lmpo",
"singleMonthly":0,
"twoPeopleMonthly":0,
"familyMonthly":0}