http $interceptor $state properties for toState

456 views Asked by At

I currently have a httpInterceptor and I can access the current state name via:

$injector.get('$state').current.name

But what I want to get is the state it is going too and I can't find the property

$injector.get('$state').unknown // what is the **toState** property

to elaborate further, I'm using ionic and Im showing a loading indicator on the requests and it allows me to have the $ionicLoading in one spot

.factory('loaderInterceptor', ['$rootScope', '$injector', function ($rootScope, $injector) {
    return {
        request: function(config) {
            $rootScope.$broadcast('loading:show', $injector.get('$state').current.name);
            return config;
        },
        response: function(response) {
            $rootScope.$broadcast('loading:hide');
            return response;
        }
    };
}]) 

$rootScope.$on('loading:show', function(e, fromState) {
    var loadingOptions = {
        template: '<i class="icon ion-loading-c"></i>\n<br/>\nloading...',
    };

    if(fromState === 'login')
    {
        var loadingOptions = {
            template: '<i class="icon ion-loading-c"></i>\n<br/>\nSigning in...',
            animation: 'fade-in',
        };
    }

    $ionicLoading.show(loadingOptions)
});

$rootScope.$on('loading:hide', function() {
    $ionicLoading.hide()
});

I want to selectively change the loading indicators text based on the to and from states so I keep the $ionicLoading in one spot.

0

There are 0 answers