Window.location.href causes 10 $digest() iterations reached


#1

Hi there guys.

I’ve come across an issue that I haven’t found a lot of info on in the forums.

I am using application states to handle navigation between screens (states) in my app. However I need to change the path programmatically in some instances and hence used window.location.href however when I use this my console has a few Angular errors 10 $digest() iterations reached etc.

If I take this out and add an a tag with href and click it, the redirect is fine with no errors, but setting it via window causes an infinite loop it seems.

I do need to set the path programmatically so can someone recommend a way to do this that wouldn’t cause these issues?

Many thanks.
Ed


#2

I’m not sure if this error is normal but I recommend you to use $state.go(‘statename’) to change state.


#3

Thank you very much that worked perfectly :smile:

For anyone else ever experiencing this issue…

Add $state to your controller dependancy array and then programmatically set the path be using $state.go(‘NameOfYourState’)

Thanks again!


#4

I didn’t mention that there’s a small difference between this and window.location.href. I checked the AngularJS documentation and window.location.href will fully reload the page whereas $state.go() won’t. So the latter is better to provide a good user experience (not white screen flash while changing page) but it’s good to know.