错误TypeError:从离子形式提交数组值时,无法读取未定义的属性“值”

时间:2018-08-13 13:46:15

标签: ionic-framework ionic2

我有一个具有此数组格式的数组值的表单,因为我不知道如何动态添加表单输入,因此必须手动执行。现在,当我尝试提交表单时,此错误显示为 ERROR TypeError:无法读取未定义的属性'value'

post.html                          

     <ion-item class="mylist chat-item item-remove-animate item-avatar item-icon-right list card animated fadeInUp">
        <ion-input type="text" readonly  name="party" placeholder="APC"  value="apc"></ion-input>
        <ion-input type="number" placeholder="Total Votes" name="vote" #vote></ion-input>

    </ion-item>

    <ion-item class="mylist chat-item item-remove-animate item-avatar item-icon-right list card animated fadeInUp">
        <ion-input type="text" readonly name="party"  value="pdp"></ion-input>
      <ion-input type="number" placeholder="Total Votes" name="vote" #vote></ion-input>
       </ion-item>

<ion-item class="mylist chat-item item-remove-animate item-avatar item-icon-right list card animated fadeInUp">
<ion-input type="text" readonly  name="party"  value="apga"></ion-input>  
<ion-input type="number" placeholder="Total Votes" name="vote" #vote></ion-input>
</ion-item>    

post.ts

@ViewChild("party") party;
@ViewChild("vote") vote; 

@ViewChild("phones")phones; 


submit(){
let data = {
            party: this.party.value,
            vote:   this.vote.value, 
            phone:   this.phones.value

          };

}

请问如何传递这些数组值?

谢谢

1 个答案:

答案 0 :(得分:0)

使用ngModel

post.html

<ion-input type="number" placeholder="Total Votes" name="vote" [(ngModel)]="party"></ion-input>

post.ts

 export class Post {
  party;

  constructor() {}

  submit(){
    let data = { 
      party: this.party };
      }
    }

check this example