Using history.pushState in Angular results in "10 $digest() iterations reached. Aborting!" error

1.2k Views Asked by At

I'm trying to change the url in my app from "http://www.test.com/foo" to "http://www.test.com/bar+someVariable" (somevariable is a string that I recieve from an http request inside bar's controller) using history.pushState() . In my routes I enabled html5mode and everything works fine. I'm also using location.path() to switch between views and controllers as instructed in the docs. Now once the app switches view and controller I added history.pushState(null,null,"/bar"+somevariable) to "/bar"'s controller. Everything works and the url is updated but in the console I receive the "10 $digest() iterations reached. Aborting!" error. I suspect that activating the history.pushState function is somehow interfering with angular's $location or $route service.

What is the correct way to use history.pushState() within angular without receiving the $digest error?

By the way I'm using angular 1.0.3

Thanks ahead, Gidon

2

There are 2 best solutions below

0
On

It is hard to know for sure without seeing the relevant source, but this is a common issue in older versions of IE (8 and 9 mostly I think). The solution that worked for me a few weeks ago when I encountered this (and may work for you if you're using IE) was changing my anchor tags in my navigation.

I had:

<a href="#"></a>

what fixed it:

<a href=""></a>
2
On

Change the path with

$location.path('/newValue')

See: http://docs.angularjs.org/guide/dev_guide.services.$location