简体   繁体   English

Angular.js停止执行(可能是一般的JavaScript错误)

[英]Angular.js stops execution (probably general javascript error)

I developed a web portal where users can log in, manage their account stuff, and so on. 我开发了一个Web门户,用户可以在其中登录,管理其帐户资料等。 Technically, it's a JSP/Servlet application running on Tomcat, delivering pages as templates. 从技术上讲,它是在Tomcat上运行的JSP / Servlet应用程序,将页面作为模板交付。 Each site has an angular app with Controllers, etc. and loads data from JSON-Service (Spring MVC). 每个站点都有一个带有Controllers等的角度应用程序,并从JSON-Service(Spring MVC)加载数据。 It's not the classical "single page app" but a "single page per service" app (each page has it's own angular app with sub-views, directives, etc.) 它不是传统的“单页应用程序”,而是“每项服务单页”应用程序(每个页面都有它自己的带有副视图,指令等的角度应用程序)

That all works great, but from time to time I'm facing with a strange error, where javascript-execution seems to stop completely (see screenshot http://i.stack.imgur.com/EF28q.png ). 一切都很好,但有时我会遇到一个奇怪的错误,即javascript执行似乎完全停止了(请参阅屏幕快照http://i.stack.imgur.com/EF28q.png )。 The green ajax-loader should be hidden by angular expression, you see the curly braces in breadcumb navigation and content, success and error-messages appear both, but should be hidden. 绿色的Ajax加载程序应通过角度表达式隐藏,您会看到面包导航和内容中的花括号,成功消息和错误消息同时出现,但应该隐藏。

After some hours of debugging I found out: 经过几个小时的调试,我发现:

  • The error only accurs when javascript-file is minified (I've got a local tomcat running uncompressed and single javascript-files) 仅当缩小javascript文件时错误才会出现(我的本地tomcat运行未压缩的单个javascript文件)
  • There is absolutely no console.log or so (I'm strictly using $log.info instead) 绝对没有console.log左右(我严格使用$ log.info代替)
  • There is no javascript-error in console 控制台中没有javascript错误
  • It's very hard to get this error in Firefox 在Firefox中很难得到此错误
  • It occurs when user are switching sites (full page refresh) quickly 当用户快速切换站点(刷新整个页面)时发生
  • It occurs in Internet Explorer 10 when switching compatibility mode/document mode 切换兼容模式/文档模式时,它会在Internet Explorer 10中发生

I followed the angular guidelines for Internet Explorer, so I prefixed all directives with data-*, etc. and I followed the "Note on minification" ( http://docs.angularjs.org/tutorial/step_05 ), so my angular controller/services/directives follow the bracket notation: app.controller('Ctrl', ['$scope', '...', function($scope, ...){}]); 我遵循了Internet Explorer的角度指南,因此在所有指令前都加上了data- *等,然后遵循“缩小提示”( http://docs.angularjs.org/tutorial/step_05 ),因此我的角度控制器/ services / directives遵循方括号表示法:app.controller('Ctrl',['$ scope','...',function($ scope,...){}]);

Any help would be greatly appreciated 任何帮助将不胜感激

Florian 弗洛里安

you can try this: 您可以尝试以下方法:

App.controller('Ctrl', ['$scope', '$http', ...... ,
  function ($scope, $http, ......) {

}]);

you need to use this way to avoid $scope , $http, ... parameters be compressed 您需要使用这种方式来避免$ scope,$ http等参数被压缩

Seems like the angular execution has not even started. 似乎角度执行尚未开始。 Because of the sporadic nature of the error, I would consider some timing problem with the DOM. 由于错误的偶发性,我将考虑DOM的一些时序问题。 Do you use RequireJS for async script loading? 您是否使用RequireJS进行异步脚本加载?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM