0

I was facing some issue with @angular/http while importing in app.module.ts.

Tried with below code

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

But unable to access get method like below

'this.http.get("http://jsonplaceholder.typicode.com/users")

But in some tutorials, i see the code like below

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

On trying, i'm getting error like 'Cannot find module '@angular/http'

this.http.get("http://jsonplaceholder.typicode.com/users").
      map((response) ⇒ response.json()).
      subscribe((data) ⇒ console.log(data))

I expect something like above..

3
  • 1
    @angular/common/http Commented Sep 3, 2019 at 9:48
  • 2
    this is a bit silly question in my opinion. Should perhaps look at the documentation, as compiler clearly tells you that you are trying to import from wrong place ;) Commented Sep 3, 2019 at 9:50
  • This got resolved.. I need to use import { HttpClientModule } from '@angular/common/http'; in app.module.ts and import { HttpClient } from '@angular/common/http'; in components/service.. This is a recent change made by angular it seems.. Thanks :) Commented Sep 3, 2019 at 10:05

1 Answer 1

1

@angular/http has been removed starting with version 8.0.0 (Source: docs).

Use @angular/common/http instead.

To update your apps:

  • Replace HttpModule with HttpClientModule (from @angular/common/http) in each of your modules.
  • Replace the Http service with the HttpClient service.
  • Remove any map(res => res.json()) calls. They are no longer needed.

For more information about using @angular/common/http, see the HttpClient guide. (Source: docs)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.