Tried to get JSON data from the model but it is not working. Only it is working when i use this.products.allproduct['product1'];. But in my application, I am passing the object name. So, depends on passing object name data will appear.
If i use this.products.allproduct[prd]; not working. How to resolve this issue.
app.component.html:
<button (click)="getData('product1')">Product 1</button>
<button (click)="getData('product2')">Product 2</button>
<button (click)="getData('product3')">Product 3</button>
<div>
{{showData}}
</div>
app.component.ts:
getData(prd: string|number) {
this.showData = this.products.allproduct[prd];
}
demo: https://stackblitz.com/edit/angular-ivy-kng5nw?file=src%2Fapp%2Fapp.component.ts
Its array of objects and showing correctly. Use ngFor for loop on the inner array.
<div *ngFor="let row of showData;let i = index;">
{{row.name}}
</div>