I am trying to use $ ionicLoading with Angular UI Router permission. The idea is that when a new route / state is requested, the load mode appears during data resolution, and then disappears when resolution ends, and a new state is created.
router
.state('tab.locations', { url: '/locations', cache: false, views: { 'locations-tab': { templateUrl: 'js/locations/tab-locations.html', controller: 'LocationsCtrl as vm' } }, resolve: { locationsResource: 'Locations', locations: function(locationsResource) { return locationsResource.all(); } } })
Without permission, one recommended method is to use $httpProvider.interceptors to broadcast events to show and hide the loading screen. Like this:
$ ionicConfigProvider
$httpProvider.interceptors.push(function($rootScope) { return { request: function(config) { $rootScope.$broadcast('loading:show'); return config }, response: function(response) { $rootScope.$broadcast('loading:hide'); return response } } })
runBlock
$rootScope.$on('loading:show', function() { $ionicLoading.show({template: '<ion-spinner></ion-spinner>'}) }); $rootScope.$on('loading:hide', function() { $ionicLoading.hide() });
This works great when not using resolves. But when the resolution is enabled, the boot screen is no longer displayed.
I tried broadcasting loading:show on $stateChangeStart if a solution is present, but this also does not work.
Are there other interceptors or state change events that I need to broadcast loading:show and loading:hide in order to make $ionicLoading work with permission?
source share