Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular $resource update method not found

Tags:

angularjs

I'm following the Angular main page and I've extended $resource to add the update method like this:

angular.module('user', ['ngResource']).
factory('User', function($resource) {
  var User= $resource('/user/:id', {
    update: {
      method: 'PUT'
    }
  });

  User.prototype.update = function(cb) {
    return User.update({  // this line throws the error
      id: this.id
    }, angular.extend({}, this, {
      _id: undefined
    }), cb);
  };

However running:

$scope.user.update()

throws a TypeError: Object function h(a){v(a||{},this)} has no method 'update'

I can't see what I'm missing right now, any help appreciated

like image 237
plus- Avatar asked Jan 15 '23 12:01

plus-


1 Answers

I found the issue in fact I need to pass an empty object for the paramDefaults arg:

var User= $resource('/user/:id', {}, {
    update: {
      method: 'PUT'
    }

}
like image 157
plus- Avatar answered Jan 25 '23 23:01

plus-