AngularJS 代码在开发者工具关闭时不执行 InternetExplorer

AngularJS code not executing InternetExplorer when Developer Tools are closed

不幸的是,我偶然发现我的应用程序有问题。在 Internet Explorer 中 运行 时。

我早些时候发现它可能与 console.log 问题有关,但我的代码中没有任何地方 console.log。但是,当打开控制台(F12 开发人员工具)时,应用程序按预期运行。

会不会和$parent.$on函数有关?

 $scope.$parent.$on("updateCart", function (e) {
        shoppingCartService.getItems().then(function (d) {

                vm.items = d;

        });
    });

这不可能与此相关,我相当确定它实际上是 console.log,但在您意想不到的地方。

您可以在没有开发人员控制台的情况下通过警告所有错误来调试 JavaScript:

window.onerror = function(msg, url, linenumber) {
    alert('Error message: '+msg+'\nURL: '+url+'\nLine Number: '+linenumber);
    return true;
}

或者通过包含 Firebug 精简版:https://getfirebug.com/firebuglite


更新:如果错误仍然没有出现,请尝试覆盖 AngularJS 的异常处理程序:(另请参阅 )

YOURAPP.factory('$exceptionHandler', function() {
  return function(exception, cause) {
    alert('Error message: '+exception.message+'\nURL: '+exception.fileName+'\nLine Number: '+exception.lineNumber+'\nCause: '+cause);
  };
});