Ionic framework 如何在Appery ionic应用程序中添加选择组件和选择选项的值
我想以编程方式在类型选择组件中列出3个选项,并在离子应用程序中获取所选选项值Ionic framework 如何在Appery ionic应用程序中添加选择组件和选择选项的值,ionic-framework,appery.io,Ionic Framework,Appery.io,我想以编程方式在类型选择组件中列出3个选项,并在离子应用程序中获取所选选项值 <ion-list> <ion-item> <ion-label>Countries</ion-label> <ion-select [(ngModel)]="selectedCountry" (ngModelChange)="onSelect()"> <ion-option *ngFor="let ite
<ion-list>
<ion-item>
<ion-label>Countries</ion-label>
<ion-select [(ngModel)]="selectedCountry" (ngModelChange)="onSelect()">
<ion-option *ngFor="let item of countries" [value]="item.id">{{ item.value }}</ion-option>
</ion-select>
</ion-item>
</ion-list>
“selectedCountry”是初始选定值,在本例中,索引为1的国家/地区位于数组国家/地区中
public selectedCountry: any;
this.selectedCountry = this.countries[1].id;
您可以使用javascript Array.push为国家/地区动态添加价值
this.countries.push({ id: 4, value: 'USA' });
您可以在selectedCountry中使用event(ngModelChange)=“onSelect()”
获取更改的值
public onSelect(): void {
console.log(this.selectedCountry);
}
以下是如何做到这一点的步骤:
- 将
选择
组件放到页面上
- 在“属性”面板集中,单击放置组件上的
选项
子组件:
至ng model
和viewData.gender
到ng选项
gender.id作为viewData.gender中性别的gender.name。genderOptions
- 在页面集的
函数中init
$scope.viewData={ 性别:0,, 性别选择:[ {id:0,名称:'Male'}, {id:1,名称:'Female'}], };
public onSelect(): void {
console.log(this.selectedCountry);
}