In my app.module().run(), I set an onerror message to pop a toastr message whenever a javascript error is encountered.
I would like this to work across my entire ngApp. Is that possible?
The following code pops a toast because asdf is invalid JavaScript.
angular.module("app").run(['notificationFactory', '$window',
function (notificationFactory, $window) {
$window.onerror = function (errorMsg, url, lineNumber) {
notificationFactory.error(errorMsg);
};
asdf
}]);
But if I put 'asdf' into a controller, $window.onerror doesn't fire.
Is it possible to catch this with a global onerror call?
App.run is in my app.js file, and loads before my controllers.
Within my controller, I can't seem to get $window.onerror to work at all. I tried moving the onerror function to the controller. I also tried to see if an img tag would generate the error to no avail.
<img ng-src="someFileThatDoesntExist.png" />