我构建了一个RESTFul应用程序,并使用Angular作为我的观点。我想用资源,因为是它最好的方法,我跟着怎么对的,并取得了一定的调整由我自己来包含头API令牌,代码结束这样的:AngularJS资源调用多次
fcbMixApp.factory('Resources', ['$resource',
function ($resource) {
return {
seminary: function (apiToken) {
return $resource('api/seminaries/:seminary', {}, {
save: {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + apiToken
}
},
update: {
method: 'PUT',
headers: {
'Authorization': 'Bearer ' + apiToken
}
}
});
},
attendant: function (apiToken) {
return $resource('api/attendants/:attendant', {}, {
save: {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + apiToken
}
},
update: {
method: 'PUT',
headers: {
'Authorization': 'Bearer ' + apiToken
}
}
});
}
}
}]);
但是,当我打电话它在我的控制器上是这样的:
var Seminary = Resources.seminary(User.getAuthData().access_token);
我不指望该行向我的api发出任何请求,但它确实如此。我的代码如下:
Seminary.query(function (data) {
$scope.seminaries = data;
});
所以我最后打了两个电话。
什么即时做错了,或者我应该改变什么。
在此先感谢。
感谢行设置与AUTH afther登录的头,但我的主要问题及其出于某种原因查询其执行两次击中两次我的API服务器 – bitgandtter