mishraoft mishraoft - 1 year ago 43
Javascript Question

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

I am using angula js and php in project
I want to create a form there is multiple input type that is group wise in single form like

name email phone
name email phone
name email phone
name email phone
name email phone

there is not a certain group it can be 10 to 50 so i want to create it in loop
1: How to create in loop
2: How to upload on server

Please help me Thank you


you can use 'ng-repeat' on $scope :

<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" />

in your controller:

suppose we can set number of inputs and we store it in $scope.numberOfInputs :

$scope.items = [];

$scope.myFunc = function(){

    for (i = 0; i < $scope.numberOfInputs.length; i++) { 

         $scope.items.push({id:i,name:'', email:''});


then $scope.items could be send with angular $http service to php! and then for converting it to array use json-decode() . after that use php's foreach loop to iterate trough this array and save each one separatly!