Search code examples
angularjsangular-resourcengresource

ngResource $save is wiping out models


I create a new model with new MyModel({description: 'default'})

Later, I save it.

$scope.myModel.$save(function(updated){
   do stuff here?
});

My problem is that the $save method is wiping out all fields. Why would that happen?

$scope.myModel.$save(function(updated){
   updated.description - undefined
   $scope.myModel.description - undefined
});

The ONLY thing I've found that works right now is this:

var copy = angular.copy($scope.myModel);
$scope.myModel.$save(function(updated){
   copy.description - not undefined
});

This seems to contradict the docs. What's going on?


Solution

  • Check your server side, I think you don't have description field in your server side model. So what happend? $scope.myModel is passed to server and updated by response object, response object does not contain description field