简体   繁体   中英

How to pass in multiple objects to $resource.save in angularjs

Currently my normal save looks like this (where personObj is being saved):

PersonService.save({ PersonId: personId }, personObj, function (data) {

                //nothing to do here

            }, function (error) {
                console.log("error in saving injury!");
                $scope.error = error;
            });

Is there a way I could pass in another object to be saved?

I would make it just one combined object but I need to have two seperate objects as this is what the back-end function looks like:

public async Task<IHttpActionResult> PostPerson(int aid, Person person, Status status)
{

I can change the back-end function, though I feel as if there is some easy angular option that I'm missing

You can do something like this instead:

function success(response) {
  // Do whatever here.
}

function error(err) {
  console.log('error in saving injury!');
  $scope.error = error;
}

PersonService.save({ PersonId: personId }, personObj, success, error);
PersonService.save({ PersonId: personId }, potherPersonObj, success, error);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM