Reputation: 555
In my template, I would like to pass an object parameter with a dynamic key.
<li *ngFor="let item of items | keys">
<a [routerLink]="[url, {objectKey: item.key}]">
{{ item.key }}{{ item.value }}
</a>
</li>
In this example, the objectKey is a property of my object, but because it's javascript, it takes it as a string 'objectKey' ...
Upvotes: 2
Views: 2991
Reputation: 9780
<li *ngFor="let item of items | keys">
<a [routerLink]="['/url', item.key]"> //<-- arguments should be array of
elements that form your url
{{ item.key }}{{ item.value }}
</a>
</li>
Upvotes: 3
Reputation: 6124
Use square brackets (if EcmaScript 6 is used):
{[objectKey]: item.key}
Upvotes: 2