【问题标题】:"@angular/http/index has no exported member of HTTP_PROVIDERS"“@angular/http/index 没有 HTTP_PROVIDERS 的导出成员”
【发布时间】:2017-07-05 09:34:12
【问题描述】:

依赖关系

ma​​in.ts 文件

我想导入HTTP_PROVIDERS,但它给了我一个错误

"@angular/http/index 没有 HTTP_PROVIDERS 的导出成员"

我附上了 package.json 和 main.ts 文件的图片

【问题讨论】:

    标签: angular typescript visual-studio-code


    【解决方案1】:

    HTTP-PROVIDERS 不再使用。将 HttpModule 导入您的 ngModule 并将其添加到您的导入中。

    import { HttpModule } from '@angular/http';
    
    @NgModule({
      imports: [
        ...
        HttpModule,
      ],
      declarations: [...],
      bootstrap: [ .. ],
      providers: [ ... ],
    })
    

    我建议您始终查看 angular.io 页面以获取当前信息。例如,here Http 的使用以及所需的一切都已描述:)

    在要使用http的服务中,导入Http并将其注入到构造函数中:

    import { Http } from '@angular/http';
    
    // ...
    
    constructor(private http: Http) { }
    

    【讨论】:

    • 那么我应该为 HttpServices @AJT_82 使用哪个提供者
    • HttpModule 包括:) 也更新了我的答案。检查我提供的链接,它包含您在应用程序中使用 Http 所需的所有信息 :)
    【解决方案2】:

    您的主模块应导入包含 HTTP 提供程序的 HttpModule。这是最近的做法。

    import { HttpModule } from '@angular/http';
    
    @NgModule({
      declarations: [],
      imports: [
        // ...,
        HttpModule,
      ],
      providers: [],
    })
    export class AppModule{
    }
    

    【讨论】:

    • 那么我应该为 HttpServices 使用哪个提供者 @mathias247
    【解决方案3】:

    只是添加。 它特别是 HttpModule 而不是 HTTPModule 或 HTTPmodule 或任何东西。

    【讨论】:

      【解决方案4】:

      HttpModule –

      Http deprecate @angular/http in favour of @angular/common/http.
      

      旧一:HttpModule 导入自——

      import { HttpModule } from '@angular/http';
      

      新一:HttpClientModule 导入表单 -

      import { HttpClientModule } from '@angular/common/http';
      

      它们都支持 HTTP 调用,但 HTTP 是较旧的 API,将 最终被弃用。

      新的 HttpClient 服务包含在 HttpClientModule 中 用于在 Angular 应用程序中发起 HTTP 请求和响应。这 HttpClientModule 是 HttpModule 的替代品。

      【讨论】:

        猜你喜欢
        • 2016-10-05
        • 2018-11-25
        • 2019-05-27
        • 1970-01-01
        • 2017-10-02
        • 2017-07-07
        • 2018-03-05
        • 2018-09-25
        • 2021-03-10
        相关资源
        最近更新 更多