I am trying to build a drop down with a few values.
However, on selecting a value, I want to make an API call that takes an id.
In my component.ts, I have an array of values:
values = [
{ id: 3432, name: "Recent" },
{ id: 3442, name: "Most Popular" },
{ id: 3352, name: "Rating" }
];
In my template, I am using that array as follows:
<select>
<option *ngFor="let v of values" [value]="v">
{{v.name}}
</option>
</select>
However, on picking a value from the drop down, how can I access the id
property? I want to use that in my function getPhotosByType(id)
.
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…