【问题标题】:HTML get textfield and checkbox content/valueHTML 获取文本字段和复选框内容/值
【发布时间】:2018-11-10 19:53:46
【问题描述】:

我的 HTML 有点问题,我无法从 HTML 获取数据到 TS。 我想保存所有文档并将其发送到我的数据库。 我得到了类似(HTML)的东西:

  <h3>Part 1 : General Information</h3>
  <ion-list>
    <ion-item>
      <ion-label>Date</ion-label>
      <ion-datetime displayFormat="MMM DD YYYY" [(ngModel)]="date"></ion-datetime>
    </ion-item>

    <ion-item>
      <ion-label stacked>First Name</ion-label>
      <ion-input type="text" aria-placeholder="First Name" placeholder="First Name"></ion-input>
    </ion-item>

    <ion-item>
      <ion-label stacked>Last Name</ion-label>
      <ion-input type="text" aria-placeholder="Last Name" placeholder="Last Name"></ion-input>
    </ion-item>

    <ion-item>
      <ion-label>Birthdate</ion-label>
      <ion-datetime displayFormat="MMM DD YYYY" [(ngModel)]="birthdate"></ion-datetime>
    </ion-item>

我在保存时获取这些数据并将其推送到这样的列表(TS)中:

public key: string = 'Save1';
public save: string[] = new Array();
public checkedValue = document.querySelector('.medical-form');
saveQuestionnaire(){
  for ( var _isave in this._symptoms ) {
      this.save.push(this.symptoms[_isave]);
      console.log("Number of symptom (27)");
  }
  console.log('TEST QUERY SELECTOR', this.checkedValue);
  console.log("this.save",this.save)
  this._storage.set(this.key,this.save);
  this.save = null;
}

我不知道如何获得这些信息。我应该使用 $scope 吗?

感谢您的宝贵时间和帮助。

【问题讨论】:

    标签: javascript html angularjs ionic-framework ionic3


    【解决方案1】:

    您应该在 .ts 文件的范围内使用 ngModel 和变量,例如:

    <ion-item>
          <ion-label stacked>First Name</ion-label>
          <ion-input type="text" aria-placeholder="First Name" placeholder="First Name" [(ngModel)]="firstName" name="firstName"></ion-input>
        </ion-item>
    
        <ion-item>
          <ion-label stacked>Last Name</ion-label>
          <ion-input type="text" aria-placeholder="Last Name" placeholder="Last Name" [(ngModel)]="lastName" name="lastName">           </ion-input>
    </ion-item>

    你应该在类的范围内设置变量:

    public firstName: string = "";
    public lastName: string = "";
    console.log(this.firstName);

    【讨论】:

    • 我必须把参数放在任何地方,比如 [(ngModel)] ?感谢您的回复
    • 对于离子输入标签,基本方式是使用 [(ngModel) 的方式,并且 name 属性也很重要,对于组件的更多疑问,您可以阅读 ionic API 文档,例如:@ 987654321@
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-12
    • 1970-01-01
    • 2012-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多