如何使用angularJS发送表单字段中的数组

如何使用angularJS发送表单字段中的数组,angularjs,field,angular-ngmodel,Angularjs,Field,Angular Ngmodel,我想在表单中插入动态字段 例如: 我有一个字段列表,如: <input type="text" name="names[]" class="name-1"> <input type="text" name="names[]" class="name-2"> <input type="text" name="names[]" class="name-1"> 在jQuery中,我只需要序列化所有表单并发送它,比如$(“#myForm”).serializ

我想在表单中插入动态字段

例如: 我有一个字段列表,如:

<input type="text" name="names[]" class="name-1">
<input type="text" name="names[]"  class="name-2">
<input type="text" name="names[]"  class="name-1">

在jQuery中,我只需要序列化所有表单并发送它,比如
$(“#myForm”).serialize()。

但是,我不知道我怎样才能做到这一点

有人知道吗


在angular中,我只知道使用指令ng模式,但我不能这样做:
ng mode=“myform.name[]”angular是一个面向数据模型的框架。您可以绑定您的模型(ej:array of value)以查看TrHough ng model和ng repeat,从而直接提交您的绑定模型。Angular是一个面向数据模型的框架。您可以绑定您的模型(ej:array of value)以查看Though ng model和ng repeat,然后直接提交绑定的模型

<form ng-submit="submitMyForm()">
    <div class="form-group">
        <label class="control-label ">Input1</label>
        <input class="form-control" type="text" name="input1" ng-model="input1"/>
    </div>
    <div class="form-group">
        <label class="control-label ">Input2</label>
        <input class="form-control" type="text" name="input2" ng-model="input2"/>
    </div>
</form>
app.controller('MyCtrl', ['$scope', function MyController ($scope) {

    $scope.input1 = 'Pre-set value of input 1';
    $scope.input2 = 'Pre-set value of input 2';

    $submitMyForm = function()
    {
        console.log('input1 value: ' + $scope.input1);
        console.log('input2 value: ' + $scope.input2);
    }
}]);

试着这样做:

<form ng-submit="submitMyForm()">
    <div class="form-group">
        <label class="control-label ">Input1</label>
        <input class="form-control" type="text" name="input1" ng-model="input1"/>
    </div>
    <div class="form-group">
        <label class="control-label ">Input2</label>
        <input class="form-control" type="text" name="input2" ng-model="input2"/>
    </div>
</form>
app.controller('MyCtrl', ['$scope', function MyController ($scope) {

    $scope.input1 = 'Pre-set value of input 1';
    $scope.input2 = 'Pre-set value of input 2';

    $submitMyForm = function()
    {
        console.log('input1 value: ' + $scope.input1);
        console.log('input2 value: ' + $scope.input2);
    }
}]);

我已经找到了解决方案,并在这里:

/*--------------------------------------------------------------
*资料来源:http://www.shanidkv.com/blog/angularjs-adding-form-fields-dynamically
*作者:穆罕默德·沙尼德shanidkannur@gmail.com
**********谢谢,穆罕默德**********
*黑客:Wilowayne De La Cruzwilo0087@gmail.com
---------------------------------------------------------*/
var app=angular.module('angularjs-starter',[]);
应用程序控制器('MainCtrl',函数($scope){
$scope.fields=[{name:'employed-name-1'},{name:'employed-name-2'}];
$scope.addNewChoice=函数(){
var newItemNo=$scope.fields.length+1;
$scope.fields.push({'name':'employed-name-'+newItemNo});
};
$scope.removeChoice=函数(){
var lastItem=$scope.fields.length-1;
$scope.fields.splice(最后一项);
};
});

-
添加字段
{{fields}}

我已经找到了解决方案,请看这里:

/*--------------------------------------------------------------
*资料来源:http://www.shanidkv.com/blog/angularjs-adding-form-fields-dynamically
*作者:穆罕默德·沙尼德shanidkannur@gmail.com
**********谢谢,穆罕默德**********
*黑客:Wilowayne De La Cruzwilo0087@gmail.com
---------------------------------------------------------*/
var app=angular.module('angularjs-starter',[]);
应用程序控制器('MainCtrl',函数($scope){
$scope.fields=[{name:'employed-name-1'},{name:'employed-name-2'}];
$scope.addNewChoice=函数(){
var newItemNo=$scope.fields.length+1;
$scope.fields.push({'name':'employed-name-'+newItemNo});
};
$scope.removeChoice=函数(){
var lastItem=$scope.fields.length-1;
$scope.fields.splice(最后一项);
};
});

-
添加字段
{{fields}}

我相信您正在寻找ng repet这里是官方的ng repet examle我相信您正在寻找ng repet这里是官方的ng repet examle这个例子不适用于我,因为我不知道我可以有多少字段“name”。可以是4个或7个字段,这取决于其他变量。这个示例对我来说没有运行,因为我不知道我可以有多少个字段“name”。可以是4或7个字段,这取决于其他变量。