如何将窗口注入角度2.1.0 [英] How to Inject Window into Angular 2.1.0
问题描述
在早期版本的Angular 2中,我可以通过添加
对于提供者数组。 由于升级到最新的稳定版本的角度2(2.1.0)现在抛出控制台错误 compiler.umd.js:14268Uncaught错误:无法解析所有LoginComponent的参数(AuthService,UserMessagesService,?)。 在参数列表中我试图注入Window对象。 尝试: export class HomeModule {} 在您的组件中: {提供:Window,useValue:window } $>
@NgModule({
声明:[...],
导入:[...],
提供者:[
{provide:windowObject,useValue:window}
]
})
code>构造函数(@Inject(windowObject)窗口:窗口})
In the earlier RC releases of Angular 2 I was able to inject the window object by adding
{provide: Window, useValue: window}
To the providers array.
Since upgrading to the latest stable release of angular 2 (2.1.0) this now throws a console error
compiler.umd.js:14268Uncaught Error: Can't resolve all parameters for LoginComponent: (AuthService, UserMessagesService, ?).
The ? in the parameter list is where I am trying to inject the Window object.
Try with:
@NgModule({
declarations: [...],
imports: [...],
providers: [
{ provide: "windowObject", useValue: window}
]
})
export class HomeModule {}
in your component:
constructor(@Inject("windowObject") window: Window})
这篇关于如何将窗口注入角度2.1.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!