0
나는 AngularJS와의 GET 및 POST 요청을 처리하는 서비스를 만든 그러나 문제는 내 컨트롤러에 있습니다HTTP 서비스 캐치 오류 각도 JS
app.js
AuthenticationService.Login(function (_data) {
$rootScope.showPreloader = false;
console.log(_data)//works fine when call is succes
},function (error){
console.log(error)//not executed when error is thrown
});
authentication.service.js
function Login(callback) {
$http({
method: "GET",
url: "/auth/getRoles",
headers: {
"Accept-Language": "en-US, en;q=0.8",
"Content-Type": "application/json;charset=UTF-8"
}
}).then(function (_response) {
return _response.data;
var serverData = response.data;
callback(serverData);//getting respone is controller when succes
}, _handleError);
};
function _handleError(_error) {
console.log(_error)//console prints on error
return _error//controller never recevies the return statement
};
문제가 결코 어떤 도움을 크게
http://blog.ninja-squad.com/2015/05/28/angularjs-promises/을 읽으십시오. –