如何从 ionic 4 ion-select 中获取选定值

Ami*_*deo 1 ionic4

我试图从 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>
Run Code Online (Sandbox Code Playgroud)

home.page.ts 文件

    countryChange(country : Country) {
        console.log(country.id) ;
    }
Run Code Online (Sandbox Code Playgroud)

Rah*_*ani 6

在 ts 文件中尝试一下:

countryChange($event) {
    console.log($event.target.value) ;
}
Run Code Online (Sandbox Code Playgroud)

这将为您提供选定的值。