angular.js:14642 TypeError: Cannot read property 'then' of undefined when calling back-end service from angular
angular.js:14642 TypeError: Cannot read property 'then' of undefined when calling back-end service from angular
我正在使用 angular 调用后端服务,但遇到错误。响应到达我的服务,但由于上述承诺错误,我无法从那里获得对我的 angular 控制器的响应。
angular 服务
function userRegister(data) {
$http.post('/api/user/register',data).then(function(response) {
console.log(response); //the success response comes here
return response;
});
}
angular 控制器
vm.register = function register() {
console.log(vm.user);
commonService.userRegister(vm.user).then(function (response) {
console.log(response); //the promise error comes here
});
}
有人可以帮我解决这个问题吗?
你应该 return
你的服务也
function userRegister(data) {
return $http.post('/api/user/register',data).then(function(response) {
console.log(response); //the success response comes here
return response;
});
}
我正在使用 angular 调用后端服务,但遇到错误。响应到达我的服务,但由于上述承诺错误,我无法从那里获得对我的 angular 控制器的响应。
angular 服务
function userRegister(data) {
$http.post('/api/user/register',data).then(function(response) {
console.log(response); //the success response comes here
return response;
});
}
angular 控制器
vm.register = function register() {
console.log(vm.user);
commonService.userRegister(vm.user).then(function (response) {
console.log(response); //the promise error comes here
});
}
有人可以帮我解决这个问题吗?
你应该 return
你的服务也
function userRegister(data) {
return $http.post('/api/user/register',data).then(function(response) {
console.log(response); //the success response comes here
return response;
});
}