How to get ion-select text

醉酒当歌 提交于 2020-01-17 07:27:28

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!