简体   繁体   中英

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. Technically, it's a JSP/Servlet application running on Tomcat, delivering pages as templates. Each site has an angular app with Controllers, etc. and loads data from 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 ). 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.

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)
  • There is absolutely no console.log or so (I'm strictly using $log.info instead)
  • There is no javascript-error in console
  • It's very hard to get this error in Firefox
  • It occurs when user are switching sites (full page refresh) quickly
  • It occurs in Internet Explorer 10 when switching compatibility mode/document mode

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, ...){}]);

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

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. Do you use RequireJS for async script loading?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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