Skip to content Skip to sidebar Skip to footer

How To Properly Overwrite The Exceptionhandler In Angularjs?

For an app I'm using a skeleton that is very similar to https://github.com/angular/angular-seed. I've tried something like this, in services.js: 'use strict'; /* Services */ ang

Solution 1:

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.

Solution 2:

try this example

http://jsfiddle.net/STEVER/PYpdM/

var myApp = angular.module('myApp', ['ng']).provider({

    $exceptionHandler: function(){
        var handler = function(exception, cause) {
            alert(exception);
            //I need rootScope here
        };

        this.$get = function() {
            return handler;
        };
    }
});

myApp.controller('MyCtrl', function($scope, $exceptionHandler) {
    console.log($exceptionHandler);
    throw"Fatal error";
});

Post a Comment for "How To Properly Overwrite The Exceptionhandler In Angularjs?"