XHRBackend扩展中的未定义提供程序窗口

时间:2017-01-17 17:06:50

标签: angular dependency-injection

我的appModule看起来或多或少是这样的:

@NgModule({
  declarations: [ ],
  providers: [
    WINDOW_PROVIDER,
    { provide: XHRBackend, useClass: AuthenticationConnectionBackend },
  ],
  bootstrap: [ AppComponent ]
})
export class AppModule { }

WINDOW_PROVIDER的位置如下:

import { ValueProvider } from '@angular/core';

export const WINDOW_PROVIDER: ValueProvider = {
  provide: 'Window',
  useValue: window
};

最后,AuthenticationConnectionBackend就是这个:

export class AuthenticationConnectionBackend extends XHRBackend {

  private window;

  constructor(_browserXhr: BrowserXhr, _baseResponseOptions: ResponseOptions,
      _xsrfStrategy: XSRFStrategy, @Inject('Window') injectedWindow: Window) {
    super(_browserXhr, _baseResponseOptions, _xsrfStrategy);

    // injectedWindow = undefined;
    this.window = injectedWindow;
  }
}

问题是,一旦angular运行AuthenticationConnectionBackend构造函数, injectWindow 未定义,我需要将其分配给服务的某个变量才能进行测试上课。

谢谢!如果您需要一些额外的信息,请不要犹豫!

0 个答案:

没有答案