0
votes

I'm developing my app in visual studio 2015 using ionic template and when I use:

.run(function ($rootScope, $state, AuthService) {
    $rootScope.$on('$stateChangeStart', function (event,next, nextParams, fromState) {

        if (!AuthService.isAuthenticated()) {
            if (next.name !== 'login') {
                event.preventDefault();
                $state.go('login');
            }
        }
    }); 
});

I get an error when testing the app. This is the error I get:

0x800a139e - JavaScript runtime error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting! Watchers fired in the last 5 iterations: []

1
AuthService.isAuthenticated is a synchronous method? - Yerken
but i don't understand AuthService.isAuthenticated is a synchronous method. am new to angualar - Rais
please post the code of AuthService - Yerken
i have posted AuthService in this link jsfiddle.net/nrroq8y8 - Rais

1 Answers

0
votes

i fixed it with the following code

.run(function ($rootScope, $state, AuthService) {
    $rootScope.$on('$locationChangeSuccess', function (event, next, nextParams, fromState) {

        if (!AuthService.isAuthenticated()) {
            if (next.name !== 'login') {
                event.preventDefault();
                $state.go('login');
               // return;
            }
        }
    });
});