AngularJS CRUD - export.update() 未在服务器控制器中调用

AngularJS CRUD - export.update() not calling in server controller

我正在使用以下 Yeoman 完整堆栈 AngularJS NPM:generator-angular-fullstack

从客户端控制器调用更新时,我收到以下错误:Error: undefined is not a function (evaluating 'User.update')我希望在我的 Web Inspector 日志中看到以下内容:

'5586c4e7214a22b5efbd1672'
'updateUser Called'  <-- Never routes to server controller

server/api/route:

//Tried PATCH and PUT
router.patch('/:id', auth.isAuthenticated(), controller.update);
//router.put('/:id', auth.isAuthenticated(), controller.update);

server/api/controller:

exports.update = function(req, res, next) {  
    console.log('updateUser Called');   
};

client/app/controller:

 'use strict';

 angular.module('demoApp')
 .controller('SandboxCtrl', function ($scope, $http, $location, Auth, User)       {

 $scope.getCurrentUser = Auth.getCurrentUser;

 $scope.user = {};
 $scope.profiles = {};
 $scope.allergens = {};

 $http.get('/api/users/me').success(function (user) {
  $scope.user = user;
  $scope.profiles = user.profiles;

  console.log(user.name);
  console.log(user.profiles);
 });

 // Update existing User
 $scope.update = function () {
  var user = $scope.user;

  console.log(user._id);

  User.update(function () {
     $location.path('/' + user._id);
  }, function (errorResponse) {
        $scope.error = errorResponse.data.message;
     });
   };
});

/Client/User/Factory:

'use strict';

 angular.module('demoApp')
   .factory('User', function ($resource) {
     return $resource('/api/users/:id/:controller', {
       id: '@_id'
 },
 {
  changePassword: {
    method: 'PUT',
    params: {
      controller:'password'
    }
  },
  update: {   //<-- I was missing this! 
    method: 'PATCH'        
  },
  get: {
    method: 'GET',
    params: {
      id:'me'
    }
   }
   });
 });

在 AngularJS NPM generator-angular-fullstack 中,factory/service 隐藏在 /client/components/auth/user 下。service.js

为现有工厂添加必要的对象句柄解决了这个问题。

update: {   //<-- I was missing this! 
method: 'PATCH'        
},