【问题标题】:Inject Http in Angular 4.0.0在 Angular 4.0.0 中注入 Http
【发布时间】:2017-05-06 18:38:08
【问题描述】:

当我尝试在引导应用程序模块之前调用 ajax 请求时。我得到了。

  let injector = ReflectiveInjector.resolveAndCreate([
        Http,
        BrowserXhr,
        {provide: RequestOptions, useClass: BaseRequestOptions},
        {provide: ResponseOptions, useClass: BaseResponseOptions},
        {provide: ConnectionBackend, useClass: XHRBackend}
      ]);
      this._http = injector.get(Http);

【问题讨论】:

标签: angular


【解决方案1】:

您需要将 HttpModule 注册到您的应用程序。 从'@angular/http'导入{ HttpModule};

@NgModule({
  imports: [
    HttpModule
  ],
  declarations: [AppComponent],
  bootstrap:    [AppComponent]
})
export class AppModule {
}

【讨论】:

    猜你喜欢
    • 2017-12-25
    • 2016-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-17
    • 2017-09-12
    • 2017-09-02
    • 2016-10-25
    相关资源
    最近更新 更多