"@ angular / http / index does not have an exported member HTTP_PROVIDERS"

Dependencies

enter image description here

file main.ts

enter image description here

I want to import HTTP_PROVIDERS , but this gives me an error that

"@ angular / http / index does not have an exported member HTTP_PROVIDERS"

I added the package.json image and the main.ts file .

+6
source share
4 answers

HTTP-PROVIDERS no longer used. Import the HttpModule into your ngModule and add it to your import.

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

I suggest you always check the angular.io page for current information. For example, here is the use of Http and everything you need is described :)

In the service you want to use http, you import Http and enter it into your constructor:

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

The main module should import the HttpModule , which contains the HTTP provider. This is the latest way to do this.

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

Just add. Its specifically an HttpModule , not an HTTPModule or HTTPmodule or anything else.

0
source

HttpModule -

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

Old: HttpModule imported from -

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

NEW One: imported form HttpClientModule -

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

Both of them support HTTP calls, but HTTP is an older API and will eventually become obsolete.

The new HttpClient service is included in the HttpClientModule, which is used to initiate an HTTP request and responses in corner applications. HttpClientModule is a replacement for HttpModule.

0
source

Source: https://habr.com/ru/post/1264294/


All Articles