如何在角度js中以单个形式创建多个组输入类型


How to create multiple group input type in single form in angular js

我在项目中使用angula js和php我想创建一个表单,在单个表单中有多个分组输入类型,例如

姓名 电子邮件 电话姓名 电子邮件 电话姓名 电子邮件 电话姓名 电子邮件 电话姓名 电子邮件 电话

没有某个组可以是 10 到 50,所以我想循环创建它1:如何在循环中创建2:如何在服务器上上传

请帮助我谢谢

你可以在$scope上使用'ng-repeat':

<input  ng-model="numberOfInputs" type="text"/>
<button ng-click="myFunc()"> set number of inputs! </button>
<div ng-repeat="item in items">
    <input ng-model="item.name" type="text" />
    <input ng-model="item.phone" type="text" />
</div>

在控制器中:

假设我们可以设置输入的数量并存储它在 $scope.输入数中:

$scope.items = [];
$scope.myFunc = function(){
    for (i = 0; i < $scope.numberOfInputs.length; i++) { 
         $scope.items.push({id:i,name:'', email:''});
    }
}

然后$scope.items可以通过 Angular $http 服务发送到 PHP! 然后要将其转换为数组,请使用 json-decode() .之后使用PHP的 foreach循环通过这个数组迭代并单独保存每个数组!