Forms 向AngularJS中的对象数组添加字段
我有一个表单,其中包含一个ng repeat,其中包含一些需要传递给服务器的输入隐藏字段。 这是页面的代码:Forms 向AngularJS中的对象数组添加字段,forms,angularjs,angularjs-scope,dynamic-arrays,Forms,Angularjs,Angularjs Scope,Dynamic Arrays,我有一个表单,其中包含一个ng repeat,其中包含一些需要传递给服务器的输入隐藏字段。 这是页面的代码: <form ng-controller="FrmController" method="post"> <div class="orderlist"> <table class="table gas">
<form ng-controller="FrmController" method="post">
<div class="orderlist">
<table class="table gas">
<thead>
<tr>
<th scope="col" ng-click="orderByField='image'; reverseSort = !reverseSort">Immagine
<span ng-show="orderByField == 'image'" class="listorder">
<span ng-show="!reverseSort"><i class="fa fa-sort-desc"></i> </span>
<span ng-show="reverseSort"><i class="fa fa-sort-asc"></i></span>
</span>
</th>
[...]
</thead>
<tbody id="gasbody" ng-repeat="product in products | filter: searchQuery | orderBy:orderByField:reverseSort" class="repeated-item">
<tr>
<input type="hidden" name="form-x-id" ng-model="form.form-x-id">
我需要以以下格式发送数据:
form-1-id: value
form-2-id: value2
form-3-id: value3
$scope.form = {form-1-id: value,
form-2-id: value2,
form-3-id: value3, ...
... form-n-id: valuen}
其中n表示ng重复的长度
ecc
如何向绑定到ng模型的$scope动态添加字段?
可能吗
谢谢我不太清楚,你想要什么? 你想要ng的索引重复吗 您可以像这样使用$index
<input name="form-{{$index}}-id" type="Hidden" ng-model="form[$index]">
当然,您必须将form={}更改为form=[]第二种解决方案是最好的$scope.form.pushnewItem。谢谢
form-1-id: value
form-2-id: value2
form-3-id: value3
$scope.form = {form-1-id: value,
form-2-id: value2,
form-3-id: value3, ...
... form-n-id: valuen}
<input name="form-{{$index}}-id" type="Hidden" ng-model="form[$index]">
$scope.addToForm=function(newItem){
$scope.form.push(newItem)
}