Hi,
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.
Generally I prefer this style as well, but in this case it doesn’t matter. When all you’re dealing with is strings, [value]="foo" and value="{{foo}}" are equivalent.
It doesn’t. b isn’t in scope when you’re trying to use it, so it will always be undefined.
<ion-option *ngFor="let b of benchList" [value]="b">{{b.bench}}</ion-option>
Now your control’s value will be the bench object, containing both id and name.
onChange()
{
let DonorName: any = this.AddDonation.controls.formControlName.value;
alert(DonorName);
} when I tried this I got nothing, So I changed formControlName to DonorID like below
onChange()
{
let DonorName: any = this.AddDonation.controls.DonorID.value;
alert(DonorName);
} this time I got DonorD value, but I need DonorName in the text format.