javascript - Ionic 中的动态形式并获取 ng-model 的值

标签 javascript angularjs ionic-framework

我想创建一个动态表单,我想从 JSON 数据创建表单。我可以创建一个表单,但我想访问该动态创建的表单并在提交按钮上获取模型(输入字段)的值。 我为此创建了一个 fiddle ( https://jsfiddle.net/anujsphinx/dpzgeyt8/2/ )。想要获得每个字段的 ng-model 值。 我在 HTML 中做错了

 <ion-view view-title="Search" ng-app="myAp">
  <ion-content ng-controller="SearchCtrl">
    <h1>Submit</h1>
    <span class="input-label">Username</span>
                    <input type="text" ng-model="loginuser.use" name="text" placeholder="Your Username" required>
    <span class="input-label">Email Id</span>
                    <input type="email" ng-model="loginuser.email" name="email" placeholder="Your Username" required>
    <div data-ng-repeat="item in data track by $index">
     <span class="input-label">{{item.name}} </span>
                    <input type="{{item.type}}" ng-model="newVar" name="email" placeholder="{{item.placeholder}}" required> {{newVar}}
    </div>
    <button type="button" ng-click="checkResult()">
        Submit
    </button>
  </ion-content>
</ion-view>

最佳答案

这是获取所有表单元素值的方法。 添加新的表单元素并在表单中添加输入字段。

<form name="newForm">
...   //input elements
</form>

添加一个循环以获取表单中所有元素的值

$scope.checkResult = function(){
    var newForm = document.newForm;
    for(i=0;i<newForm.elements.length;i++){
        console.log(newForm.elements[i].value);
    }  
  }

希望对你有帮助

关于javascript - Ionic 中的动态形式并获取 ng-model 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40543101/

相关文章:

javascript - jQuery 方法找不到选择器

javascript - 如何在javascript中获取值查询字符串并将其放入文本框中

javascript - 从数组中生成一个随机索引但排除一个。 javascript

javascript - ngFlow 到 Forimidable node.js 服务器

angularjs - 在运行时获取模块和 Controller |服务|指令名称

javascript concat 运行时间

angularjs 日期过滤器忽略撇号

html - 使上传文件在 div 上不可见

css - 栏副标题按钮上的小图标

html - <select> 标签在 ionic 中的某些 android 设备上不起作用