angular ui router - 10 digest iterations reached in angularjs when using $state.go -


i using angular ionic.

i not want user have login again in case logged in , did not logout last time used application. reason, using local storage check if user logged in. tried putting code in run block.

$rootscope.$on('$statechangestart', function (event, tostate, toparams, fromstate, fromparams) {     if($localstorage.userinfo){         $state.go('deployment');   //this line 270 of app.js          event.preventdefault();                 return;          }       }) 

but gives error says:

rangeerror: maximum call stack size exceeded     @ scope.$broadcast (ionic.bundle.js:23414)     @ object.transitionto (ionic.bundle.js:40804)     @ object.go (ionic.bundle.js:40671)     @ app.js:270     @ scope.$broadcast (ionic.bundle.js:23412)     @ object.transitionto (ionic.bundle.js:40804)     @ object.go (ionic.bundle.js:40671)     @ app.js:270     @ scope.$broadcast (ionic.bundle.js:23412)     @ object.transitionto (ionic.bundle.js:40804) 

also,

error: [$rootscope:infdig] 10 $digest() iterations reached. aborting! watchers fired in last 5 iterations: [] http://errors.angularjs.org/1.3.13/$rootscope/infdig?p0=10&p1=%5b%5d     @ ionic.bundle.js:8755     @ scope.$digest (ionic.bundle.js:22973)     @ scope.$apply (ionic.bundle.js:23198)     @ done (ionic.bundle.js:18351)     @ completerequest (ionic.bundle.js:18541)     @ xmlhttprequest.requestloaded (ionic.bundle.js:18482) 

how fix these errors?

config in app looks this:

.config(function($stateprovider,$urlrouterprovider){   $stateprovider   .state('login',{     url:'/login',     templateurl:'templates/login.html',     controller:'loginctrl'   })    .state('deployment',{     url:'/deployment',     templateurl:'templates/deployment.html'   })   .state('bill',{     url:'/bills',     templateurl:'templates/bills.html'   }) $urlrouterprovider.otherwise('/login'); }) 

edit 1: after reading this github link

i changed if condition

 if($localstorage.userinfo != null && tostate.name != 'deployment'){             $state.go('deployment');              event.preventdefault();                     return;              } 

and maximum call stack size exceeded went away.

but still left 10 digest iterations reached.

edit:2

i changed

`$urlrouterprovider.otherwise('/login');` in app.js 

to

$urlrouterprovider.otherwise(function ($injector) {            var $state = $injector.get('$state');             $state.go('login');         });  

after pretty sure have missed condition in if statement i.e

   if($localstorage.userinfo != null && tostate.name != 'deployment') 

can please might have missed leading infinite loop ?

looking @ documentation of ui-router http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$state $statechangestart event can cancelled event.preventdefault() initiating transition before cancel old one.

hence since tostate.name isn't documented property seems fail again , again on condition , keep spawning new state changes.

try:

if($localstorage.userinfo != null && tostate.$current.name != 'deployment'){     event.preventdefault();     $state.go('deployment');     return; } 

Comments

  1. @admin

    Our dental team is committed to excellent oral health for our patients. We offer comprehensive dental care and brilliant cosmetic dentistry to EAST HARTFORD and the surrounding areas.

    Regards,
    Dentist In East Hartford, CT

    ReplyDelete

  2. @admin

    These are the values that we hold central to our practice. We create beautiful smiles as we focus on the overall health of your mouth. We encourage you to call or email us with any questions or concerns that you have so that we can better serve you.

    Regards,
    Dentist In unionville, CT

    ReplyDelete
  3. @admin

    Our doctors or dentists are to facilitate their advance techniques and educational experience, which provide patients with the best alternatives for oral health. Our team and dentists maintain to prepare themselves to provide maximum satisfaction for patients.
    Regards,
    Dentist In New Britain, CT

    ReplyDelete

Post a Comment

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -