Questions tagged «angular2-injection»

4
在没有构造函数注入的情况下获取服务实例
我@Injectable在引导程序中定义了一项服务。我想在不使用构造函数注入的情况下获取服务实例。我尝试使用,ReflectiveInjector.resolveAndCreate但这似乎创建了一个新实例。 我要这样做的原因是我有一个由许多组件派生的基本组件。现在,我需要访问一个服务,但是我不想将其添加到ctor中,因为我不想在所有派生组件上注入该服务。 TLDR:我需要一个 ServiceLocator.GetInstance<T>() 更新: RC5 +的更新代码:存储进样器实例以在组件中使用
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.