如何设置离子选项的默认选定值? [英] How to set default selected value of ion-option?

查看:88
本文介绍了如何设置离子选项的默认选定值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < ion-选择[(ngModel)] =company.form> 
< ion-option * ngFor =let form of forms[value] =form[selected] =true> {{form.name}}< / ion-option>
< / ion-select>

我也尝试过使用选中但是这也行不通。我怎样才能做到这一点?

  Cordova CLI:6.4.0 
Ionic Framework版本:2.0.0-rc.3
Ionic CLI版本:2.1.13
Ionic App Lib版本:2.1.7
Ionic App脚本版本:0.0.45


解决方案

您不需要使用选定的属性或[选择]它不是必需的

 < ion-select [(ngModel)] =company.form.idname =company.form.id> 
< ion-option * ngFor =let form of formsvalue ={{form.id}}>
{{form.name}}
< / ion-option>
< / ion-select>


I'm using Ionic v2 and I can not set the selected value when showing the page.

<ion-select [(ngModel)]="company.form">
    <ion-option *ngFor="let form of forms" [value]="form" [selected]="true">{{form.name}}</ion-option>
</ion-select>

I've tried with checked, too but that isn't work either. How can I do this?

Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.3
Ionic CLI Version: 2.1.13
Ionic App Lib Version: 2.1.7
Ionic App Scripts Version: 0.0.45

解决方案

You do not need to work with the attribute selected or [selected] it is not necessary

<ion-select [(ngModel)]="company.form.id" name="company.form.id">
    <ion-option *ngFor="let form of forms" value="{{ form.id }}">
      {{ form.name }}
    </ion-option>
</ion-select>

这篇关于如何设置离子选项的默认选定值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆