How to implement my service in ExceptionHandler

I used my service in other places that were automatically entered using angular 2. I want to use the same service in ExceptionHandler. But the service does not send data to the server. I went through debuger and my service is calling.

class MyExceptionHandler extends ExceptionHandler { rbJSLogger: RBLoggerService; constructor() { super(null,null); var injector = ReflectiveInjector.resolveAndCreate([ RBLoggerService, JSONP_PROVIDERS, Http, ConnectionBackend, HTTP_PROVIDERS ]); this.rbJSLogger = injector.get(RBLoggerService); } call(error, stackTrace = null, reason = null){ // console.error(stackTrace); this.rbJSLogger.searchBy("asd"); } } 
+2
angular
Jun 03 '16 at 8:38
source share
1 answer

ExceptionHandler update has been renamed to ErrorHandler stack overflow

orgiginal

This code

 var injector = ReflectiveInjector.resolveAndCreate([...]); 

creates a new independent injector that knows nothing about the services provided in your Angular applications.

You might want to introduce the injector used by Angular in your application, for example

 class MyExceptionHandler extends ExceptionHandler { rbJSLogger: RBLoggerService; constructor(injector:Injector) { super(null,null); this.rbJSLogger = injector.get(RBLoggerService); } call(error, stackTrace = null, reason = null){ // console.error(stackTrace); this.rbJSLogger.searchBy("asd"); } } 

or simply

 class MyExceptionHandler extends ExceptionHandler { rbJSLogger: RBLoggerService; constructor(private rbJSLogger:RBLoggerService) { super(null,null); } call(error, stackTrace = null, reason = null){ // console.error(stackTrace); this.rbJSLogger.searchBy("asd"); } } 
+2
Jun 03 '16 at 8:42 on
source share



All Articles