3

I am writing my first app in angularjs and it gives me error

Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.3.13/$rootScope/infdig?p0=10&p1=%5B%5D
    at ionic.bundle.js:8890
    at Scope.$digest (ionic.bundle.js:23108)
    at Scope.$apply (ionic.bundle.js:23333)
    at bootstrapApply (ionic.bundle.js:10275)
    at Object.invoke (ionic.bundle.js:13012)
    at doBootstrap (ionic.bundle.js:10273)
    at bootstrap (ionic.bundle.js:10293)
    at angularInit (ionic.bundle.js:10187)
    at ionic.bundle.js:34952
    at HTMLDocument.trigger (ionic.bundle.js:11571)(anonymous function) @ ionic.bundle.js:20434
ionic.bundle.js:23336 Uncaught Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.3.13/$rootScope/infdig?p0=10&p1=%5B%5D
ionic.bundle.js:20434 Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.3.13/$rootScope/infdig?p0=10&p1=%5B%5D
    at ionic.bundle.js:8890
    at Scope.$digest (ionic.bundle.js:23108)
    at Scope.$apply (ionic.bundle.js:23333)
    at done (ionic.bundle.js:18486)
    at completeRequest (ionic.bundle.js:18676)
    at XMLHttpRequest.requestLoaded (ionic.bundle.js:18617)(anonymous function) @ ionic.bundle.js:20434
ionic.bundle.js:23336 Uncaught Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!

My culprit app.js code is

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

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

If I remove the last part of redirecting user to login page if he is not authenticated, I dont get the error. During the bootup it indeed gets into the loop multiple times if I start with

domain.com/ 

Why does this happen?

raju
  • 4,788
  • 15
  • 64
  • 119

0 Answers0