我正在尝试将默认值设置为离子选择选项,单击单选按钮“否”。
<ion-select class="brand" name="selectBrand" [(ngModel)]="selectBrand" required>
<ion-option *ngFor="let brand of Brand;" [value]="brand.val">{{brand.name}}</ion-option>
</ion-select>
<ion-col>
<ion-list radio-group name="checkBox" [(ngModel)]="autoManufacturers">
<ion-item>
<ion-label>Yes</ion-label>
<ion-radio [value]="true"></ion-radio>
</ion-item>
<ion-item>
<ion-label>No</ion-label>
<ion-radio (ionSelect)="radioChecked()" [value]="false"></ion-radio>
</ion-item>
</ion-list>
所以当我点击单选按钮中的“否”时,我需要一个默认数组[1]。
Brand = [
{
"name": "Avin",
"val" : "Avin"
},
{
"name": "Amul",
"val" : "Amul"
},
{
"name": "Arokya",
"val" : "Arokya"
},
{
"name": "Thirumala",
"val" : "Thirumala"
}];
radioChecked(){
console.log("hi");
selectBrand = this.Brand[0];
}
当我尝试这样做时,我的价值空虚,有人可以帮助我
答案 0 :(得分:0)
就像评论中@PierreDuc所说的那样,使用页面中的属性来保存所选值,这样您就可以使用默认值对其进行初始化。
组件代码:
@Component({...})
export class YourPage {
public selectedBrandValue: any;
// ...
constructor(...) {
// Initialize the select with the first value by default
this.selectedBrandValue = this.Brand[0].val;
}
// ...
}
查看:
<ion-select class="brand" [(ngModel)]="selectedBrandValue" required>
<ion-option *ngFor="let brand of Brand;" [value]="brand.val">{{brand.name}}</ion-option>
</ion-select>