我试图将选项列表动态加载到选择输入中。 我得到的错误如下:
Error in ./PhonePage class PhonePage - caused by: Failed to execute 'setAttribute' on 'Element': '[[ngModel]]' is not a valid attribute name.
这是我的phone.ts代码
@Component({
selector: 'page-phone',
templateUrl: 'phone.html'
})
export class PhonePage {
selectedValue: number;
optionList: Array<{value:number, text: string}> = [];
constructor(public navCtrl: NavController, public navParams: NavParams) {
this.navCtrl = navCtrl
this.initOptionList();
}
moveToEmail(){
this.navCtrl.push(EmailPage)
}
initOptionList(){
this.optionList.push({value: 1,text:"FR +33"});
this.optionList.push({value: 1,text:"BE +32"});
this.optionList.push({value: 1,text:"LU +352"});
this.optionList.push({value: 1,text:"CH +41"});
this.optionList.push({value: 1,text:"GB +44"});
this.optionList.push({value: 1,text:"IE +353"});
this.optionList.push({value: 1,text:"NL +31"});
this.optionList.push({value: 1,text:"ES +34"});
this.optionList.push({value: 1,text:"PT +351"});
this.optionList.push({value: 1,text:"IT +39"});
this.optionList.push({value: 1,text:"DE +49"});
this.optionList.push({value: 1,text:"DK +45"});
this.optionList.push({value: 1,text:"MT +356"});
this.optionList.push({value: 1,text:"GP +590"});
this.optionList.push({value: 1,text:"GF +594"});
this.optionList.push({value: 1,text:"MQ +596"});
this.optionList.push({value: 1,text:"YT +262"});
this.optionList.push({value: 1,text:"NC +687"});
this.optionList.push({value: 1,text:"PF +689"});
this.optionList.push({value: 1,text:"RE +262"});
}
}
这是我的html页面的代码,我试图循环。 我在数组中推送选项。
<ion-select [[ngModel]]="selectedValue">
<ion-option *ngFor="let item of optionList" value="{{item.value}}">{{item.text}}</ion-option>
</ion-select>
答案 0 :(得分:6)
您必须将ngModel
声明为[(ngModel)]="selectedValue"
(括号内的括号)
而你已声明为[[ngModel]]="selectedValue"
(括号内括号)。