问题
I am trying to get the ion-select option's text. Here is my object structure
{
"data": [
{
"id": "203",
"bench": "abc"
},
{
"id": "205",
"bench": "def"
},
{
"id": "207",
"bench": "ghi"
}
]}
Here is my HTML
<ion-select name="bench" formControlName="bench">
<ion-option *ngFor="let b of benchList" value="{{b.id}}">{{b.bench}}</ion-option>
</ion-select>
How could i get the 'b.bench' . I need both id and bench. I got the id by using value attribute but I can't find a way to get bench value. Please help me with this problem. Thanks.
回答1:
You can set value attribute as an object.
<ion-select name="bench" formControlName="bench">
<ion-option *ngFor="let b of benchList" [value]="b">{{b.bench}}</ion-option>
</ion-select>
In the component side:
let benchObj = formGroup.controls['bench'].value;
console.log(benchObj.bench)
来源:https://stackoverflow.com/questions/43204876/how-to-get-ion-select-text