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

后端 未结 9 1388
被撕碎了的回忆
被撕碎了的回忆 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 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.

提交回复
热议问题