当试图覆盖$exceptionHandler时,Angular Controller init上会发生7次简单的java
Simple javascript exception happens 7 times on Angular Controller init when trying to override $exceptionHandler
我编写了一个工厂来覆盖内置的$exceptionHandler,因为我计划创建一个可以从前端登录的后端服务。但是现在,我只想捕获异常,将其记录到控制台,然后抛出它,因为知道console.log
将被服务调用替换。
angular.module('exceptionOverride', []).factory('$exceptionHandler', function() {
return function(exception) {
console.log(exception);
throw exception;
};
});
在控制器的init函数中,我把
var x = n + 1
,所以它会抛出一个错误,由于n
是未定义的。
但是,在控制器初始化时,会发生以下情况:
exceptionOverride.js:4 ReferenceError: n is not defined(…)
exceptionOverride.js:4 ReferenceError: n is not defined(…)
exceptionOverride.js:4 ReferenceError: n is not defined(…)
exceptionOverride.js:4 ReferenceError: n is not defined(…)
exceptionOverride.js:4 ReferenceError: n is not defined(…)
exceptionOverride.js:4 ReferenceError: n is not defined(…)
exceptionOverride.js:4 ReferenceError: n is not defined(…)
exceptionOverride.js:6 Uncaught ReferenceError: n is not definedinit @ taxAccountNameController.js:17taxAccountNameController @ taxAccountNameController.js:12invoke @ angular.js:4478instantiate @ angular.js:4486(anonymous function) @ angular.js:9151$interpolate.compile @ angular-ui-router.js:4018invokeLinkFn @ angular.js:8789nodeLinkFn @ angular.js:8289compositeLinkFn @ angular.js:7680publicLinkFn @ angular.js:7555updateView @ angular-ui-router.js:3959directive.compile @ angular-ui-router.js:3927invokeLinkFn @ angular.js:8789nodeLinkFn @ angular.js:8289compositeLinkFn @ angular.js:7680publicLinkFn @ angular.js:7555$interpolate.compile @ angular-ui-router.js:4026invokeLinkFn @ angular.js:8789nodeLinkFn @ angular.js:8289compositeLinkFn @ angular.js:7680publicLinkFn @ angular.js:7555updateView @ angular-ui-router.js:3959(anonymous function) @ angular-ui-router.js:3921parent.$get.Scope.$broadcast @ angular.js:16311$state.transitionTo.$state.transition.resolved.then.$state.transition @ angular-ui-router.js:3311processQueue @ angular.js:14745(anonymous function) @ angular.js:14761parent.$get.Scope.$eval @ angular.js:15989parent.$get.Scope.$digest @ angular.js:15800parent.$get.Scope.$apply @ angular.js:16097done @ angular.js:10546completeRequest @ angular.js:10744requestLoaded @ angular.js:10685
angular.js:68 Uncaught Error: [$rootScope:inprog] $digest already in progress
http://errors.angularjs.org/1.4.7/$rootScope/inprog?p0=%24digestREGEX_STRING_REGEXP @ angular.js:68beginPhase @ angular.js:16346parent.$get.Scope.$digest @ angular.js:15780(anonymous function) @ angular.js:16028completeOutstandingRequest @ angular.js:5507(anonymous function) @ angular.js:5784
我的exceptionOverride
中的console.log触发7次,然后抛出异常(如预期的那样),但随后我也得到$digest already in progress
错误。
我做错了什么?
由于你覆盖了Angular的本地$exceptionHandler
,它无法完成它的工作。$exceptionHandler
包含比console.log
和throw
更多的行。它有一些代码可以暂停其他Angular服务或提供商来避免这种情况。
相关文章:
- java脚本中的谷歌地图在第二次点击时不起作用
- java-script 函数被调用两次
- 控制不止一次跳水的风格's风格使用java脚本动态,使用类
- 在两次java定时器循环后重定向访问者
- 转义符两次,java和javascript
- 在Java中处理意外的多次单击
- 如何多次调用控制器以从整体中获取数据块 - Java,Spring MVC
- 尝试让 onclick 多次调用 Java 脚本
- Spotfire Java脚本将字段拆分为唯一值,并每30秒更新一次MapChart可视化,以反映值的变化
- 如何在android中一次调用多个java脚本函数来加载webview
- 在这个java脚本动画中,第二次动画不能正常工作
- 在html.java中第一次单击后隐藏链接.禁用链接
- 如何在Java/javascript中每天更改一次变量的值
- 如何使用java脚本多次重复一个过程
- 试图跟踪多少次java脚本函数被调用
- 当试图覆盖$exceptionHandler时,Angular Controller init上会发生7次简单的java
- 使用java脚本显示最后一次看到的网页状态
- 使用Java脚本在数字表中30次更改2个随机数
- 为什么我需要在刷新浏览器后立即在textfield上单击两次才能调用Java Script中的函数?
- Java脚本函数只工作一次