获取由ng-repeat创建的动态字段的数据

时间:2015-05-04 16:04:05

标签: angularjs

我必须创建一个包含动态字段的动态向导的表单 在angularJs。

此代码如下:

<div ng-repeat="field in wizard.Wizardfields">  
            {{field.label}}
            <input type="{{field.type}}"  placeholder="{{field.label}}" ng-model="field.value" />
        </div> 
<input type="button" value="Next" ng-click="next(field)" />

现在,正在创建字段,但我无法弄清楚如何在Angular控制器的所有字段中输入数据。关于此问题的任何帮助:

修改

现在我有这个解决方案的所有字段的数据

<input type="{{field.type}}"  placeholder="{{field.label}}" ng-model="values[$index]" />

但是没有区别哪个字段的值是什么。

我的意思是它给出类似[&#34; abc&#34;,&#34; 12&#34;]的数组,而我希望它像[姓名:&#34; abc&#34;,年龄:&#34 ; 12&#34;] ......或以任何形式识别特定领域的数据......

1 个答案:

答案 0 :(得分:1)

您可以使用$ index:

将值保存到值数组中
<input type="{{field.type}}"  placeholder="{{field.label}}" ng-model="values[$index]" />

如此plunker所示。