2

I have implemented CustomReuseStrategy in Angular. I want to subscribe to an observable in shouldAttach() to determine if the route should be reattached or not. I have created an observable in a service and I need to use the service instance in CustomReuseStrategy. I tried injecting the service in the constructor and I get this error:

Can't resolve all parameters for CustomReuseStrategy

Should the constructor for the RouteReuseStrategy not have parameters? If so, how do I create the instance of the service?

ricksmt
  • 888
  • 2
  • 13
  • 34
user1613338
  • 153
  • 1
  • 2
  • 9
  • What does your app module look like? Are you declaring your service in the `providers` array? – RustyPiranha Jan 11 '18 at 00:04
  • Yes. I have declared my service in the Providers array in appmodule. I could inject this service in other components and they are working fine. Since the "CustomReuseStrategy" is a class and not a component. I couldn't inject the service through the constructor. – user1613338 Jan 11 '18 at 00:19
  • Please, provide all relevant code. The question is off-topic without it. See https://stackoverflow.com/help/mcve – Estus Flask Jan 11 '18 at 00:22

1 Answers1

2

I have resolved this by using Reflective Injector.

let injector = ReflectiveInjector.resolveAndCreate([MyService]);
this.subscriptionSvc = injector.get(MyService);
ricksmt
  • 888
  • 2
  • 13
  • 34
user1613338
  • 153
  • 1
  • 2
  • 9