如何获取离子选择文本 [英] How to get ion-select text
本文介绍了如何获取离子选择文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取ion-select选项的文本。这是我的对象结构
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"
}
]}
这是我的HTML
<ion-select name="bench" formControlName="bench">
<ion-option *ngFor="let b of benchList" value="{{b.id}}">{{b.bench}}</ion-option>
</ion-select>
我怎么能得到'b.bench'。我需要id和bench。我通过使用value属性获得了id,但是我找不到获得替换值的方法。请帮我解决这个问题。谢谢。
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.
推荐答案
您可以将 value
属性设置为对象。
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>
在组件方面:
let benchObj = formGroup.controls['bench'].value;
console.log(benchObj.bench)
这篇关于如何获取离子选择文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文