在angularJs应用程序中打开引导程序模态时,我需要更改浏览器URL,我使用的pushState()
函数是url,但它引发了以下错误:
Uncaught Error: [$rootScope: infdig] 10 $digest() iterations reached.Aborting!
Watchers fired in the last 5 iterations: [
["fn: $locationWatch; newVal: 8; oldVal: 7"],
["fn: $locationWatch; newVal: 9; oldVal: 8"],
["fn: $locationWatch; newVal: 10; oldVal: 9"],
["fn: $locationWatch; newVal: 11; oldVal: 10"],
["fn: $locationWatch; newVal: 12; oldVal: 11"]
]
http: //errors.angularjs.org/1.2.13/$rootScope/infdig?p0=10&p1=%5B%5B%22fn%3…2fn%3A%20%24locationWatch%3B%20newVal%3A%2012%3B%20oldVal%3A%2011%22%5D%5D angular-1.2.13.js:78
(anonymous function) angular-1.2.13.js:78
Scope.$digest angular-1.2.13.js:11937
(anonymous function) angular-1.2.13.js:12084
completeOutstandingRequest angular-1.2.13.js:4144
(anonymous function)
这是$location
角度服务中的错误。它已在2014年8月27日最新版本的Angular 1.3.0-beta.20中修复。请参阅问题3924和副本6976,这些都归功于此修复程序。
angular-ui团队提供了一个临时修复程序的文档:https : //github.com/angular-ui/ui-router/issues/562#issuecomment-31623003
造成此问题的原因是,Angular不会同步通知浏览器的URL更改,并且在$ browser.url()中信任其缓存的URL版本。由于$ browser.url()作为吸气剂是幂等的,因此它会不断返回真实的url,而不更新其内部内容。
为了验证这是真的,请在window.history.replaceState行之后,在提供的测试中添加此行,然后测试将通过:angular.element($ window).triggerHandler('popstate');
通过在url getter中重置lastBrowserUrl,可以在$ browser内的一行中轻松解决此问题:lastBrowserUrl = newLocation || location.href.replace(/%27 / g,“'”); 但这可能会导致不良的副作用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句