1
状態変更が発生したときに保留中の要求をすべて停止しようとしています。以下のコードは$ httpではうまく動作しますが、$ resourceでは正常に動作しません。
var cancel=$q.defer();
$http.get('api/cafservicestatus',{timeout:cancel.promise,cancel:cancel}).then(onsuccess,onerror);
function onsuccess(result) {
console.log(result)
}
function onerror(error) {
console.log(error)
}
function stopHttp() {
$http.pendingRequests.forEach(function(request) {
if (request.cancel) {
request.cancel.resolve();
}
});
}
しかし、このコードはここで$リソース では動作しません$
$resource(resourceUrl, {}, {
'query': { method: 'GET', isArray: true,timeout:$q.defer().promise,cancel:$q.defer()},
'get': {
method: 'GET',
transformResponse: function (data) {
if (data) {
data = angular.fromJson(data);
}
return data;
}
},
'update': { method:'PUT' }
});
私は考え出した$リソース
これが唯一の私がしたい特定のcontroller.Whatのための問題を解決には、一度、$ rootScope上ですべての要求をキャンセルすることですしかし、とにかく、ありがとう –