I want to show loading-mark when each request was started and hide the loading-mark automatically after the request was completed.
There are my code:
$ionicPlatform.ready(function() {
$rootScope.$on('loading:show', function() {
$ionicLoading.show({template: 'Loading...'})
});
$rootScope.$on('loading:hide', function() {
$ionicLoading.hide()
});
}
angular.module('abx.routes', []).config(function($httpProvider) {
$httpProvider.interceptors.push(['$q', '$location', '$rootScope', function($q, $location, $rootScope) {
return {
request: function(config) {
$rootScope.$broadcast('loading:show');
config.headers = config.headers || {};
if (localStorage.access_token) {
// config.headers.Authorization = 'Bearer ' + $localStorage.token;
config.headers.access_token = localStorage.access_token;
}
return config;
},
response: function(response){
$rootScope.$broadcast('loading:hide');
return response;
},
responseError: function(response) {
if (response.status === 401 || response.status === 403) {
alert('no access token error!');
}
return $q.reject(response);
}
};
}]);
})
It’s work for me on the chrome. But doesn’t work on the emulate.
Am I right?