我的离子项目中有一个下拉项目
主页.html
<ion-list>
<ion-item>
<ion-label color="danger">Location</ion-label>
<ion-select name="location" formControlName="location" >
<ion-option value=3>{{'Palarivattom'}}</ion-option>
<ion-option value=4>{{'Kadavantra'}}</ion-option>
<ion-option value=5>{{'Kaloor'}}</ion-option>
</ion-select>
</ion-item>
</ion-list>
使用 formgroup 创建表单 home.ts
{
this.formgroup=formbuilder.group({
mobile:['', Validators.compose([Validators.required,
Validators.minLength(10,), Validators.maxLength(10)])],
password:['', Validators.compose([Validators.required,
Validators.minLength(5)])],
location:['', Validators.compose([Validators.required])],
});
this.mobile=this.formgroup.controls['mobile'];
this.password=this.formgroup.controls['password'];
this.location=this.formgroup.controls['loaction'];
}
当试图获取位置值时,错误消息为“未定义”
doprint() {
console.log( this.name.value) //Ajith
console.log(this.email.value) //ajith@gmail.com
console.log(this.location.value) //undefined
}