1

我的离子项目中有一个下拉项目

主页.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
}
4

1 回答 1

0

你有一个错字

this.location=this.formgroup.controls['location'];

无论如何,标准的做法是,

doprint() {
let formItem = this.itemForm.value;
console.log(formItem.name);
console.log(name.email);
console.log(name.location) ;
}
于 2017-10-31T13:46:08.920 回答