离子选择不显示 FormBuilder 的选定选项(Ionic 3) [英] ion-select not showing selected option with FormBuilder (Ionic 3)

查看:34
本文介绍了离子选择不显示 FormBuilder 的选定选项(Ionic 3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

取下面的html

  <form [formGroup]="detailsForm">

  <ion-list>
  <ion-item>
    <ion-label>Gaming</ion-label>
    <ion-select formControlName="gaming">
      <ion-option value="nes">NES</ion-option>
      <ion-option value="n64">Nintendo64</ion-option>
      <ion-option value="ps">PlayStation</ion-option>
      <ion-option value="genesis">Sega Genesis</ion-option>
      <ion-option value="saturn">Sega Saturn</ion-option>
      <ion-option value="snes">SNES</ion-option>
    </ion-select>
  </ion-item>
  </ion-list>

  </form>

在你的组件中

this.detailsForm = this.formBuilder.group({
      gaming:['nes',Validators.required]
    });

我希望在加载视图时看到NES"作为选定选项.但是,它没有出现.如果您改为使用 [(ngModel)] ,它将起作用.

I would expect to see 'NES' as the selected option when the view is loaded. However, it does not appear. If you instead use [(ngModel)] it will work.

是我做错了什么,还是最近的 ionic 更新导致了这个问题?

Am I doing something wrong, or has the most recent ionic update caused this issue?

任何帮助都会很棒.

推荐答案

这只是3.1的问题.它要么是传递整个事件与过去的值相比的重大变化,要么与在用户交互之前组件加载时触发 ionChange (或第一件事导致第二件事)有关).暂时使用 3.0.

It's just an issue with 3.1. It's either a breaking change with passing the whole event vs. the value as it used to, or has something to do with firing ionChange when the component loads before user interaction (or the first thing is causing the second). Use 3.0 for now.

这篇关于离子选择不显示 FormBuilder 的选定选项(Ionic 3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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