angularjs - How to use $http.post within global error handling? -
i have mvc 5.0 web project angularjs 1.3 single page app components. want post mvc controller in event of unhandled angular exceptions, i'm overriding $exceptionhandler factory this:
mod.factory('$exceptionhandler', ['$http', function($http) { homecoming function(exception, cause) { console.log(exception.message); $http.post("application/catchangularerror", { exception: exception, cause: cause }); } }]);
in chrome, javascript console reports "uncaught error: [$injector:cdep] http://errors.angularjs.org/1.3.0/$injector/cdep?p0=%24rootscope%20%3c-%20%24http%20%3c-%20%24exceptionhandler%20%3c-%20%24rootscope" when load page including script. evidently, $http has dependency on $exceptionhandler, can't give $exceptionhandler dependency on $http, because creates circular dependency.
i guess can utilize jquery.ajax, i'd prefer more angular solution if 1 exists. have one?
you utilize $injector service , lookup $http service:
mod.factory('$exceptionhandler', ['$injector', function($injector) { homecoming function(exception, cause) { console.log(exception.message); var $http = $injector.get('$http'); $http.post("application/catchangularerror", { exception: exception, cause: cause }); };
angularjs angularjs-http
No comments:
Post a Comment