Reputation: 63
Module not found: Error: Can't resolve '@angular/http' even i used import {HttpClientModule} from '@angular/common/http';
Upvotes: 5
Views: 16169
Reputation: 11
import { HttpModule } from '@angular/http';
- Does not work
Try the below one -
import { HttpClientModule } from '@angular/common/http';
...
imports: [
BrowserModule,
FormsModule,
HttpClientModule
],
...
This worked for me.
Upvotes: 1
Reputation: 97
in the root AppModule
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule } from '@angular/common/http';
@NgModule({
imports: [
BrowserModule,
// import HttpClientModule after BrowserModule.
HttpClientModule,
],
declarations: [
AppComponent,
],
bootstrap: [ AppComponent ]
})
export class AppModule {}
In your Service
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable()
export class ConfigService {
constructor(private http: HttpClient) { }
getConfig() {
return this.http.get(this.configUrl);
}
}
In your Components
showConfig() {
this.configService.getConfig()
.subscribe((data: any) => {
// response...
});
}
Upvotes: 5