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



我使用以下Yeoman全栈AngularJS NPM:生成器角度全栈

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

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

服务器/api/路由:

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

服务器/api/控制器:

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

客户端/应用程序/控制器:

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

/客户/用户/工厂:

'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生成器angular fullstack中,工厂/服务隐藏在/client/components/auth/user.service.js 下

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

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

最新更新