问题描述
我已经在Angular中实现了CustomReuseStrategy.我想订阅shouldAttach()
中的一个可观察对象,以确定是否应该重新连接该路由.我在服务中创建了一个可观察对象,并且需要在CustomReuseStrategy中使用该服务实例.我尝试将服务注入构造函数中,但出现此错误:
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:
RouteReuseStrategy的构造函数应该没有参数吗?如果是这样,如何创建服务实例?
Should the constructor for the RouteReuseStrategy not have parameters? If so, how do I create the instance of the service?
推荐答案
我已经通过使用反射式注入器解决了这个问题.
I have resolved this by using Reflective Injector.
let injector = ReflectiveInjector.resolveAndCreate([MyService]);
this.subscriptionSvc = injector.get(MyService);
这篇关于如何以角度向CustomReuseStrategy中注入服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!