Cannot find the '@angular/common/http' module

后端 未结 9 1362
被撕碎了的回忆
被撕碎了的回忆 2020-12-01 04:25

I am following this fundamental tutorial on Angular about Http.

As one can see in the \"Setup: Installing the module\" section, they import the HttpClientModule as f

相关标签:
9条回答
  • 2020-12-01 04:49

    Refer to this: http: deprecate @angular/http in favor of @angular/common/http.

    0 讨论(0)
  • 2020-12-01 04:50

    Is this issue resolved.

    I am getting this error: ERROR in node_modules/ngx-restangular/lib/ngx-restangular-http.d.ts(3,27): error TS2307: Cannot find module '@angular/common/http/src/response'.

    After updating my angular to version=8

    0 讨论(0)
  • 2020-12-01 05:01

    Important Update:

    HttpModule and Http from @angular/http has been deprecated since Angular V5, should of using HttpClientModule and HttpClient from @angular/common/http instead, refer CHANGELOG.


    For Angular version previous from **@4.3.0, You should inject Http from @angular/http, and HttpModule is for importing at your NgModule's import array.

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

    Inject http at component or service

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

    For Angular version after(include) 4.3.0, you can use HttpClient from @angular/common/http instead of Http from @angular/http. Don't forget to import HttpClientModule at your NgModule's import array first.

    Refer @echonax's answer.

    0 讨论(0)
提交回复
热议问题