代码之家  ›  专栏  ›  技术社区  ›  Tonye Boro

错误类型错误:从离子中的窗体提交数组值时,无法读取未定义的属性“value”

  •  1
  • Tonye Boro  · 技术社区  · 6 年前

    我有一个表单,它的数组值采用这种数组格式,因为我不知道如何动态添加表单输入,所以我不得不手动添加。现在,当我尝试提交表单时,显示了这个错误 错误类型错误:无法读取未定义的属性“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>    
    

    邮政信箱

    @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 回复  |  直到 6 年前
        1
  •  0
  •   Sudarshana Dayananda    6 年前

    使用 ngModel .

    post.html网站

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

    邮政信箱

     export class Post {
      party;
    
      constructor() {}
    
      submit(){
        let data = { 
          party: this.party };
          }
        }
    

    check this example