node.js - Add multiple rows from same model AngularJS -
considering have list of users add system , don't want one-by-one process. want see 1 user form (name, email, password fields) , end of row see "add row" button.
by clicking on "add row" button, 1 more user form add after existing one.
how can send multiple users through 1 post request in angularjs?
you should have array of users in controller , every time press "add user" can add new user array.
the code in controller:
$scope.users = [{ name: "1" , email: "email1", password:"pas1" }, { name: "2" , email: "email2", password:"pas2"}];; $scope.adduser = function () { $scope.users.push({ name: "" , email: "", password:"" }); }; now, in html list users binding in array. adding new user every time adds new line in html views binding on parameters of new user added.
<form ng-submit="submit()"> <div class="container"> <div class="col-md-5"> <li class="list-group-item col-xs-12" data-ng-repeat="user in users"> <input type="text" class="form-control" placeholder="username" ng-model="user.name"> <input type="text" class="form-control" placeholder="password" ng-model="user.name"> <input type="text" class="form-control" placeholder="email" ng-model="user.name"> </li> <button class="col-xs-12" ng-click="adduser()">add user</button> </div> add function submit controller submit way want user array. hopes helps.
Comments
Post a Comment