0

I am working on a dynamic form in angular where the data can be multiple paths with other data where on save, it needs to send multiple post requests to server. Is this possible in angular? Here is my html ,

 <fieldset class="form-group pl-sm" ng-repeat="file in files">
   <div>
        <input type="text" class="form-control" autocomplete="off" name="fileLocation" ng-model="file.name">            
    </div>
        <input type="checkbox" class="switch-input" name="" ng-model="file.xxxx" />
        <input type="checkbox" class="switch-input" name="" ng-model="file.yyyy" />            
   <div class="col-sm-3">
        <select class="form-control" name="fileCenters" ng-model="file.centers" required>
            <option value="Development">Development</option>
            <option value="Sales">Sales</option>
        </select>
    </div>
</fieldset>
<a  href="" ng-click="addNew()">Add more </a>

I am not sure how i could save all the paths in a single post request. So essentially it has to be a json object with multiple object entirs such as

 [{
    location: 'france',
    xxxx: true,
    yyyy: false,
    center: 'sales'
   },
   {
    location: 'france',
    xxxx: true,
    yyyy: false,
    center: 'sales'
   }]

any help on angular http.post with multiple request will be great , do i need to queue up the requests with a timeout or add a callback and chain the request on success of the first request??

7
  • If you can, send the array as data in a single request $http.post(url, arrayOfObjects) Commented May 12, 2015 at 5:07
  • Do you need to send them in a specific order? If not why can't you just keep firing requests to the server. Commented May 12, 2015 at 5:11
  • I dont really need to send them in a certain order, its just that on the form, there is only one save button , upon clicking teh save, all the locations should be posted to the server. @YangLi , how would i keep firing request eg? Commented May 12, 2015 at 5:18
  • Why can't you have one path that handles all the data rather than sending multiple requests? Commented May 12, 2015 at 5:20
  • An example would certainly help. Commented May 12, 2015 at 5:21

1 Answer 1

1

You do not need to send data multiple times to the server. On submit you can send all the data at once with

$http.post(url, array).then(function(response){
    console.log(response.data);
}).error(function(){
    //If there is an error..
}).finally(function(){
    //regardless of error or not, whatever u want to do
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.