Я использую следующий YEOMAN полный стек AngularJS НПМ: generator-angular-fullstackAngularJS CRUD - export.update() не вызывая в контроллере сервера
При вызове обновления от контроллера клиента, я получаю следующее сообщение об ошибке: Error: undefined is not a function (evaluating 'User.update')
I» м ожидая увидеть следующее в моем веб-инспектора Журналы:
'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;
});
};
});
/Клиент/Пользователь/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'
}
}
});
});
Где вы определяете ** Пользователь **? Кажется, у него нет ** функции ** обновления? – Michael
Обновлен клиентский контроллер, чтобы показать, где Пользователь, если он определен. – CampbellGolf
Вы просто указали ссылку на ** Пользователь **, но не на ** заводскую/сервисную функцию ** – Michael