我正在尝试使用以下代码检查响应状态:
$scope.coach = Coach.get(function(response) {
if(response.status === 401) {
alert("Coach");
}
});
但它不起作用,任何人都可以帮忙。谢谢
答案 0 :(得分:0)
$resource.get()
需要两次回调;第二个是错误处理程序并接收响应对象:
$scope.coach = Coach.get(
function (coach) {
// ... could do something with returned data object here
},
function (res) {
alert("Coach status: " + res.status);
}
);
检查此plunker是否有一个工作示例:http://plnkr.co/edit/WHL63r?p=preview