对于一个应用程序,我使用的骨架与https://github.com/angular/angular-seed非常相似。 。
我在 services.js 中尝试过类似的方法:
'use strict';
/* Services */
angular.module('mApp.services', []).
factory('$exceptionHandler', function () {
return function (exception, cause) {
alert(exception.message);
}
});
这没有做任何事情,它似乎没有覆盖异常处理程序。
如果我尝试:
var mod = angular.module('mApp', []);
mod.factory('$exceptionHandler', function() {
return function(exception, cause) {
alert(exception);
};
});
它会覆盖整个应用程序。
如果我使用类似于默认 Angular 应用程序的骨架,如何正确覆盖异常处理程序?
最佳答案
如果不查看应用程序的其余部分,很难确定,但我猜angular.module('myApp').factory( ...
将工作。如果省略第二个参数( ,[]
),Angular 将检索现有模块以进行进一步配置。如果你保持它的 Angular ,就会创建一个新模块。
关于javascript - 如何正确覆盖AngularJS中的ExceptionHandler?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16489058/