如何正确地覆盖angularjs中的exceptionHandler? [英] How to properly overwrite the exceptionHandler in angularjs?

查看:64
本文介绍了如何正确地覆盖angularjs中的exceptionHandler?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于一个应用程序,我使用的骨架与 https://github.com/非常相似角/角种子.

For an app I'm using a skeleton that is very similar to https://github.com/angular/angular-seed.

我已经在services.js中尝试过类似的事情:

I've tried something like this, in services.js:

'use strict';

/* Services */

angular.module('mApp.services', []).
  factory('$exceptionHandler', function () {
    return function (exception, cause) {
        alert(exception.message);
    }
});

这什么也没做,似乎没有覆盖exceptionHandler.

This doesn't do anything, it doesn't seem to overwrite the exceptionHandler.

如果我尝试:

var mod = angular.module('mApp', []);

mod.factory('$exceptionHandler', function() {
  return function(exception, cause) {
    alert(exception);
  };
});

它会覆盖整个应用程序.

It overwrite the whole app.

如果我使用类似于默认角度应用程序的框架,如何正确覆盖exceptionHandler?

How can I properly overwrite the exceptionHandler if I am using a skeleton similar to the default angular app?

推荐答案

如果没有看到应用程序的其余部分就很难确定,但是我猜是 angular.module('myApp').factory(... 将起作用,如果省略第二个参数(,[] ),angular将检索一个现有模块以进行进一步配置;如果保留它,它将创建一个新模块.

It's hard to know for certain without seeing the rest of your app, but I'm guessing angular.module('myApp').factory( ... will work. If you leave out the second parameter (,[]) angular will retrieve an existing module for further configuring. If you keep it angular will create a new module.

这篇关于如何正确地覆盖angularjs中的exceptionHandler?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆