【问题标题】:How to reset value of Ion Select in Ionic 6?如何在 Ionic 6 中重置 Ion Select 的值?
【发布时间】:2022-08-09 15:39:17
【问题描述】:

我想将ion-select 值重置为空。选择后我正在导航到另一个页面,当我从该页面单击后退按钮时,ion-select 选择了该值。我希望它重置后退按钮上的离子选择。

这是我的 .html 文件代码

<ion-select #mySelect style=\"display: none\" (ionChange)=\"onOrderSelection($event)\" interface=\"action-sheet\" mode=\"ios\" [value]=\"orderTypeModel\">
      <ion-select-option *ngFor=\"let item of orderTypes\" [value]=\"item.id\">{{ item.name }}</ion-select-option>
    </ion-select>

这是组件代码

orderTypeModel = \'\';
ionViewWillEnter(): void {
  this.orderTypeModel = null;
  this.changeDetecRef.detectChanges();
}

我也尝试过用[ngModel] 代替[value],但该事件不起作用。

请建议一些方法来做到这一点?

  • 您的代码适用于[value][(ngModel)]
  • 你能创建一个stackblitz吗?

标签: javascript angular ionic-framework ionic6


【解决方案1】:

将 ngModel 添加到 ion-select :

<ion-select [(ngModel)]="MyselectItem">

当你想像这样重置它时:

这个.MyselectItem = null;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-23
    • 2021-01-08
    • 2020-06-28
    • 2022-06-22
    • 2020-10-12
    • 2019-12-24
    • 2018-02-22
    相关资源
    最近更新 更多