My use case : I am assigning a Array of Objects to select's option using ngFor as follows
<select>
<option *ngFor="let item of data" [value]="item.key">{{item.value}}</option>
<select>
and my data is
[
{
"key" : "CHV",
"value" : "Chivas"
},
{
"key" : "BLN",
"value" : "Balentines"
},
{
"key" : "BDG",
"value" : "Black Dog"
}
]
Pretty straigtforward, now what i want is to bind the item.key and item.value specified by user i.e he should be able to mention which to use for options value and label. Here's what ive tried and didn't work
<option *ngFor="let item of data; let itemlabel = optionlabel; let itemvalue = optionvalue" value="{{item.itemvalue}}">{{item.itemlabel}}</option>
optionvalue & optionlabel are string in the component as follows
optionvalue : string = 'key';
optionlabel : string = 'value';
So now when i swap them i can get key as value and vice versa. Any idea how to do so