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

时间:2015-07-28 22:14:51

标签: javascript asp.net angularjs angular-resource

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

1 个答案:

答案 0 :(得分:0)

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);