0

ngInclude的示例展示了如何更新 ngInclude 元素的 src 属性。

以类似的方式,我试图将模板路径分配给一个变量,但在 ajax 请求的回调中。分配后,我正在做$rootScope.$apply($scope.setMainTemplatePath)
我还将 $rootScope 注入到包含回调的函数中。

但我收到以下错误:

Error: 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [["fn: function (){var a=d.url();if(!n||a!=f.absUrl())n++,c.$evalAsync(function(){c.$broadcast(\"$locationChangeStart\",f.absUrl(),a).defaultPrevented?f.$$parse(a):(d.url(f.absUrl(),f.$$replace),f.$$replace=!1,h(a))});return n}; newVal: 30; oldVal: 29"],["fn: function (){var a=d.url();if(!n||a!=f.absUrl())n++,c.$evalAsync(function(){c.$broadcast(\"$locationChangeStart\",f.absUrl(),a).defaultPrevented?f.$$parse(a):(d.url(f.absUrl(),f.$$replace),f.$$replace=!1,h(a))});return n}; newVal: 31; oldVal: 30"],["fn: function (){var a=d.url();if(!n||a!=f.absUrl())n++,c.$evalAsync(function(){c.$broadcast(\"$locationChangeStart\",f.absUrl(),a).defaultPrevented?f.$$parse(a):(d.url(f.absUrl(),f.$$replace),f.$$replace=!1,h(a))});return n}; newVal: 32; oldVal: 31"],["fn: function (){var a=d.url();if(!n||a!=f.absUrl())n++,c.$evalAsync(function(){c.$broadcast(\"$locationChangeStart\",f.absUrl(),a).defaultPrevented?f.$$parse(a):(d.url(f.absUrl(),f.$$replace),f.$$replace=!1,h(a))});return n}; newVal: 33; oldVal: 32"],["fn: function (){var a=d.url();if(!n||a!=f.absUrl())n++,c.$evalAsync(function(){c.$broadcast(\"$locationChangeStart\",f.absUrl(),a).defaultPrevented?f.$$parse(a):(d.url(f.absUrl(),f.$$replace),f.$$replace=!1,h(a))});return n}; newVal: 34; oldVal: 33"]]
        at Error (unknown source)
        at Object.$digest (http://localhost:3000/assets/angular-1.0.1.min.js?body=1:85:413)
        at Object.$apply (http://localhost:3000/assets/angular-1.0.1.min.js?body=1:87:58)
        at HTMLDivElement.<anonymous> (http://localhost:3000/assets/web/angularjs/controllers.js?body=1:40:27)
        at HTMLDivElement.<anonymous> (http://localhost:3000/assets/jquery.js?body=1:3257:9)
        at HTMLDivElement.<anonymous> (http://localhost:3000/assets/jquery.js?body=1:2876:28)
        at Object.trigger (http://localhost:3000/assets/jquery.js?body=1:3145:12)
        at HTMLDivElement.<anonymous> (http://localhost:3000/assets/jquery.js?body=1:3782:17)
        at Function.each (http://localhost:3000/assets/jquery.js?body=1:659:20)
        at [object Object].each (http://localhost:3000/assets/jquery.js?body=1:272:17) 

请指出我是否遗漏了什么或做错了什么。谢谢。

4

1 回答 1

0

你不应该调用 scope.$apply 除非你正在处理 Angular 控制之外的东西。更多代码会有所帮助。

于 2012-07-12T22:04:12.667 回答