0

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: []

4
  • AuthService.isAuthenticated is a synchronous method?
    – Yerken
    Commented Feb 15, 2016 at 6:42
  • but i don't understand AuthService.isAuthenticated is a synchronous method. am new to angualar
    – Rais
    Commented Feb 15, 2016 at 6:51
  • please post the code of AuthService
    – Yerken
    Commented Feb 15, 2016 at 6:52
  • i have posted AuthService in this link jsfiddle.net/nrroq8y8
    – Rais
    Commented Feb 15, 2016 at 7:03

1 Answer 1

0

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;
            }
        }
    });
});

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.