angularjs - ngResource: Custom update method cleans the instance -


i make customer service $resource:

.factory('customer', function($resource, apiurl){     return $resource(apiurl+'customers/:id', { id: '@id' }, {         'update': {method: 'put'}     }) }) 

when update customer (that instance of customer service), , after promise resolved, customer var cleaned. why?

$scope.customer = customer.get({id: $stateparams.id}, function (){     console.log($scope.customer) // object {id: 1, name: 'john doe', ...}     $scope.customer.$update()         .then(function () {             console.log($scope.customer) // object { status: true, $promise: object, $resolved: true }         }) }); 

when update customer (that instance of customer service), , after promise resolved, customer var cleaned. why?

when $update resolves clears , updates $resource object new data. server returning empty data.

if want update without clearing object, put updated object in second argument of customer.update method.

customer.update({id: $stateparams.id}, $scope.customer); 

or modify server return updated information.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -