私はいくつかのことを試しましたが、前のリクエストが完了する前に関数が呼び出されたときにhttpリクエストをキャンセルしているようではありません。 1.5.7を使用しています。$ scope.glsuggestedが実行されるたびに、保留中のglsuggested.get()要求を取り消したいので、$ q.deferを拒否するためにいくつか試しましたが運がありません。ここで
は、私が得たものです:
// Controller.
export class BudgetController {
constructor ($scope, $q, $timeout, $log, glbudget, glsuggested) {
'ngInject';
$scope.glsuggested = function(cat) {
var _getsuggested = glsuggested.get(cat);
_getsuggested.then(function(data) {
$scope.glproducts = data;
}, function(error) {
$scope.budgetdetails = 'error';
$log.log(error);
});
};
}
}
// Service
export class GlsuggestedService {
constructor ($http, $q, $rootScope, $log) {
'ngInject';
this.$http = $http;
this.$q = $q;
this.$rootScope = $rootScope;
this.$log = $log;
}
get(category) {
var defer = this.$q.defer();
var headers = {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json'
};
var req = this.$http({
method: 'GET',
headers: headers,
url: this.$rootScope.apiurl + '/products/recommend/' + category,
timeout: defer.promise
});
var _log = this.$log.log;
req.success(function(data) {
_log('success!', data, data.id);
return defer.resolve(data);
});
req.error(function(data) {
_log('error!', data);
return defer.reject('error');
});
return defer.promise;
}
}