Hello all together,
I’m pretty new to Ionic, so dont be so hard to me
Currenly I’m coding a generic Datafactory for my API calls and I want to show an $ionicLoading-Popup everytime something is loading.
My Factory is created like this:
app.factory('DataService', function( $resource, config, CacheFactory, $ionicLoading, $translate, Interceptors, $rootScope){
return {
call : function(_key) {
var res = $resource(config.APIV2+ _key+'/:id', { id: '@id' },{
query: {
method: 'GET',
isArray: true,
cache : true,
interceptor : Interceptors
},
get: {
method: 'GET',
cache : true,
interceptor : Interceptors
}
}
)
// debugger;
return res;
}
}
});
I aditionally created an Interceptor-Factory to store the interceptors globaly and use them:
app.factory('Interceptors', function($injector, $log, $rootScope) {
// var p = $injector.get('$ionicLoading');
// console.log(p);
var responseInterceptor = {
request: function(config){
$injector.get('$ionicLoading').show({
content: 'Loading',
animation: 'fade-in',
showBackdrop: true,
maxWidth: 200,
showDelay: 0
});
return config;
},
response: function(response){
// $log.info('Reponse interception');
$injector.get('$ionicLoading').hide().then(function(){
console.log("The loading indicator is now hidden");
});
// $log.info(response);
$rootScope.$broadcast('loading:hide');
return response;
};
return responseInterceptor;
});
In my app.js I injected the Interceptors like this:
app.config(['$httpProvider', function ($httpProvider) {
$httpProvider.interceptors.push('Interceptors');
}]);
At the moment the loading Screen is not shown up. If I comment out the hiding in the response interceptor, the loading screen is working fine.
What I’m doing wrong?