【问题标题】:how to get selected value from ionic 4 ion-select如何从 ionic 4 ion-select 中获取选定值
【发布时间】:2019-09-08 13:35:46
【问题描述】:

我正在尝试从 ion-select 中获取选定的选项值 但是当我从 ion-select 中选择任何值时,我会得到未定义的值,因为我是 ionic 4 的新手。 我无法自行排序。

  <ion-item>
              <ion-label>Country</ion-label>
              <ion-select formControlName="country" (ionChange)="countryChange($event)" >
                  <ion-select-option *ngFor="let country of countries" [value]="country.value">{{country.name}}</ion-select-option>
              </ion-select>
          </ion-item>

home.page.ts 文件

    countryChange(country : Country) {
        console.log(country.id) ;
    }

【问题讨论】:

    标签: ionic4


    【解决方案1】:

    在 ts 文件中试试这个:

    countryChange($event) {
        console.log($event.target.value) ;
    }
    

    这将为您提供选定的值。

    【讨论】:

    • 非常感谢,我在代码中卡了 3 天,现在问题解决了
    • @AmitNamdeo。欢迎您。你能通过勾选标记来标记这个答案吗?
    猜你喜欢
    • 2020-03-25
    • 2018-10-28
    • 2018-01-15
    • 2019-09-19
    • 2021-05-23
    • 2018-02-22
    • 2022-08-09
    • 2019-12-02
    • 2019-09-23
    相关资源
    最近更新 更多