How to Inject my service to ExceptionHandler

Arturs Soms

I used my service in other places injected automaticaly by angular 2. I want to use the same service in ExceptionHandler. But service doesn't post data to server. I went through debuger and my service invokes.

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");
  }
}
Günter Zöchbauer

update ExceptionHandler was renamed to ErrorHandler https://stackoverflow.com/a/35239028/217408

orgiginal

This code

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

creates a new independent injector that doesn't know anything about services provided in your Angular applications.

You might want to inject the injector used by Angular in your application like

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 just

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");
  }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to inject my service into my controller angular js

From Dev

How to inject $rootScope into a service?

From Java

How to inject Document in service?

From Dev

How to inject a service to jasmine

From Dev

How to inject a controller to a service?

From Dev

Why can't I inject my service?

From Dev

how to inject service for 2 modules

From Dev

How to inject Mocks into Spring Service

From Dev

How to inject additional service to the ExceptionListener?

From Java

How to inject service into class (not component)

From Dev

How to inject service to angular constant

From Dev

How to inject $_SERVER variable into a Service

From Dev

How to inject bean in a Tapestry service

From Dev

How to inject $_SERVER variable into a Service

From Dev

How to inject bean in a Tapestry service

From Dev

how to inject service for 2 modules

From Dev

How to inject RabbitMqBundle producer into service?

From Dev

Injecting EJB with @EJB or @Inject in the service layer for my REST web service?

From Dev

Inject my own service to Activiti Api service task

From Dev

How to inject a service into app.config in AngularJS

From Dev

how to inject $cookie in custom service of angularjs?

From Dev

how to inject store in service ember.js

From Dev

How to inject a producer as a service into a RabbitMQBundle consumer?

From Dev

How to inject a service into every component in Ember JS

From Dev

How to inject service into custom ActionFilterAttribute (Web API)?

From Dev

How to get once instance of service with Inject

From Dev

How To Inject Service Into Angular 1.5 Component (No Typescript)

From Dev

How to inject service into custom ActionFilterAttribute (Web API)?

From Dev

How to inject service depending on directive attribute in angular?

Related Related

  1. 1

    How to inject my service into my controller angular js

  2. 2

    How to inject $rootScope into a service?

  3. 3

    How to inject Document in service?

  4. 4

    How to inject a service to jasmine

  5. 5

    How to inject a controller to a service?

  6. 6

    Why can't I inject my service?

  7. 7

    how to inject service for 2 modules

  8. 8

    How to inject Mocks into Spring Service

  9. 9

    How to inject additional service to the ExceptionListener?

  10. 10

    How to inject service into class (not component)

  11. 11

    How to inject service to angular constant

  12. 12

    How to inject $_SERVER variable into a Service

  13. 13

    How to inject bean in a Tapestry service

  14. 14

    How to inject $_SERVER variable into a Service

  15. 15

    How to inject bean in a Tapestry service

  16. 16

    how to inject service for 2 modules

  17. 17

    How to inject RabbitMqBundle producer into service?

  18. 18

    Injecting EJB with @EJB or @Inject in the service layer for my REST web service?

  19. 19

    Inject my own service to Activiti Api service task

  20. 20

    How to inject a service into app.config in AngularJS

  21. 21

    how to inject $cookie in custom service of angularjs?

  22. 22

    how to inject store in service ember.js

  23. 23

    How to inject a producer as a service into a RabbitMQBundle consumer?

  24. 24

    How to inject a service into every component in Ember JS

  25. 25

    How to inject service into custom ActionFilterAttribute (Web API)?

  26. 26

    How to get once instance of service with Inject

  27. 27

    How To Inject Service Into Angular 1.5 Component (No Typescript)

  28. 28

    How to inject service into custom ActionFilterAttribute (Web API)?

  29. 29

    How to inject service depending on directive attribute in angular?

HotTag

Archive