I want to bind a nested objects property name using angular interpolation
<ng-container ngFor="let item of saleDetailsAggegater.productMap | keyvalue">
<tr *ngFor="let qtyMap of item.value | keyvalue">
<td>{{ item.key }}</td>
<td>{{qtyMap.value}}</td>
<td>{{Object.keys(qtyMap)[0]}}</td>
</tr>
</ng-container>
my saledetailsAggegater object is as follows
{"productMap":{"55478":{"priceQuantityMap":{"200.00":10}}},"taxMap":{},"paymentMap":{"1":970},"total":970}
but this line is not working as expected
<td>{{Object.keys(qtyMap)[0]}}</td>
how can i achieve this?
I don't think you can use native javascript functions in your template (angular won't parse them). You can however define the function on your component, and then use that in your template:
@Component({
template: '<td>{{objectKeys(myObj)[0]}}</td>'
})
export class MyComponent {
objectKeys = Object.keys;
myObj = { displayThisKey: 'some-value' };
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With