You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If cancelOnRouteChange isn't defined, the call isn't cancelled. This is specially important when loading angular app directives. I have a redirect to login would cancel the loading of important app directives. The default behaviour should be not to cancel.
Cancelled calls were hanging the angular-loading-bar. So loading would never finish.
I didn't create a PR because these changes are easy to implement. Source code below:
angular
.module('angularCancelOnNavigateModule', [])
.config(function($httpProvider) {
$httpProvider.interceptors.push('HttpRequestTimeoutInterceptor');
})
.run(function ($rootScope, HttpPendingRequestsService) {
$rootScope.$on('$locationChangeSuccess', function (event, newUrl, oldUrl) {
if (newUrl != oldUrl) {
HttpPendingRequestsService.cancelAll();
}
});
});
angular.module('angularCancelOnNavigateModule')
.service('HttpPendingRequestsService', function ($q) {
var cancelPromises = [];
function newTimeout() {
var cancelPromise = $q.defer();
cancelPromises.push(cancelPromise);
return cancelPromise.promise;
}
function cancelAll() {
angular.forEach(cancelPromises, function (cancelPromise) {
cancelPromise.promise.isGloballyCancelled = true;
cancelPromise.resolve();
});
cancelPromises.length = 0;
}
return {
newTimeout: newTimeout,
cancelAll: cancelAll
};
});
angular.module('angularCancelOnNavigateModule')
.factory('HttpRequestTimeoutInterceptor', function ($q, HttpPendingRequestsService) {
return {
request: function (config) {
config = config || {};
if (config.timeout === undefined && config.cancelOnRouteChange) {
config.timeout = HttpPendingRequestsService.newTimeout();
}
return config;
},
responseError: function (response) {
return $q.reject(response);
}
};
});
The text was updated successfully, but these errors were encountered:
bjaraujo
changed the title
Two bugs with one stone.
Code change request.
Nov 19, 2015
This modified source code solves 2 problems.
I didn't create a PR because these changes are easy to implement. Source code below:
The text was updated successfully, but these errors were encountered: