Property 'get' does not exist on type 'HttpClientModule'
You need to use HttpClient
not HttpClientModule
to make an http request.
In app.module.ts, import HttpClientModule
(see "imports" below):
import { HttpClientModule } from '@angular/common/http';
@NgModule({
imports: [
HttpClientModule,
...
],
...
})
export class AppModule { }
Then, import HttpClient
in app.component.ts:
import { HttpClient } from '@angular/common/http';
Now, change your AppComponent Ctor from
constructor(private http: HttpClientModule){};
to
constructor(private http: HttpClient){};
app.module.ts
import { HttpClientModule } from '@angular/common/http'
@NgModule({
declarations: [
AppComponent
],
imports: [
HttpClientModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
app.component.ts
import { HttpClient } from '@angular/common/http';
@Component ({
selector:'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
results;
constructor(private http: HttpClient) {}
ngOnInit() {
this.todaydate = this.myservice.getTodayDate();
this.http.get("http://jsonplaceholder.typicode.com/users").subscribe(data => {
console.log(data);
this.results = data;
});
}
}
Change/add those code/method from header and imports
import {HttpClientModule} from '@angular/common/http';
import { HttpClient } from '@angular/common/http';
and in import section add this code:
HttpClientModule,
indicated in the pic:
Pic1
Include those header in your class where you try to access httpClient :
import { HttpClientModule } from '@angular/common/http';
import { HttpClient } from '@angular/common/http';
and for map use this code .map(res => res );
instead of .map((res: Response) => res.json() );
And from this pic you can see how to solve 'get' problem:
Pic2
For get the clear concept watch pic1 and pic2. Thank You.
Beside you get this error if you did not pay attention on the imports for HTTPClient. Usually it defaults to
import { HttpClient } from 'selenium-webdriver/http';