You cannot have a single model for several input elements, because if you change the value in any of the input fields, it will overwrite it with the last value. Assuming that you start filling out the form, starting from form1 to form3 and submit, the model will hold the value entered in the last used input field, i.e. form3.
To solve your problem, you need to use a collection, array or object (preferably an array) as your model.
Your controller will be something like this:
var JobModel = function() { return { jobs: [], addRow: function() { var model = { quantity: "", quality: "", }; this.jobs.push(model); }, save: function() { console.log(this.jobs); }, submit: function(){ for(var i=0;i<this.jobs.length;i++){ doSomeHTTPRequest(this.jobs[i]); } } }; }; $scope.jobModel = new JobModel();
Your HTML will be something like:
<button ng-click="jobModel.addRow()"> Add Job </button> <div ng-repeat="job in jobModel.jobs"> <input type="text" ng-model="job.quantity" placeholder="Quantity"> <input type="text" ng-model="job.quality" placeholder="Quality"> </div> <button ng-click="jobModel.save()"> Save Jobs </button>
To submit a form with the same name, you will need to iterate over the array of tasks and make ajax calls for each
source share