我正在使用 Angular 调用后端服务,但遇到错误。响应到达我的服务,但由于上述 promise 错误,我无法从那里获得对我的 Angular Controller 的响应。
angular.service
function userRegister(data) {
$http.post('/api/user/register',data).then(function(response) {
console.log(response); //the success response comes here
return response;
});
}
Angular Controller
vm.register = function register() {
console.log(vm.user);
commonService.userRegister(vm.user).then(function (response) {
console.log(response); //the promise error comes here
});
}
有人可以帮我解决这个问题吗?
最佳答案
您还应该退回
您的服务
function userRegister(data) {
return $http.post('/api/user/register',data).then(function(response) {
console.log(response); //the success response comes here
return response;
});
}
关于angularjs - Angular .js :14642 TypeError: Cannot read property 'then' of undefined when calling back-end service from angular,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44904408/