ion-select未显示FormBuilder(Ionic 3)中的选定选项 [英] ion-select not showing selected option with FormBuilder (Ionic 3)

查看:64
本文介绍了ion-select未显示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.

我是在做错什么,还是最近的离子更新导致了此问题?

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.

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

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