I have a problem with HTTP in Angular.
I just want to GET a JSON list and show it in the view.
im
Angular version 6 "0.6.8" rxjs version 6 "^6.0.0"
this solution is for :
"@angular-devkit/core": "0.6.8",
"rxjs": "^6.0.0"
as we all know angular is being developed every day so there are lots of changes every day and this solution is for angular 6 and rxjs 6
first to work with http yo should import it from :
after all you have to declare the HttpModule in app.module.ts
import { Http } from '@angular/http';
and you have to add HttpModule to Ngmodule -> imports
imports: [
HttpModule,
BrowserModule,
FormsModule,
RouterModule.forRoot(appRoutes)
],
second to work with map you should first import pipe :
import { pipe } from 'rxjs';
third you need the map function import from :
import { map } from 'rxjs/operators';
you have to use map inside pipe like this exemple :
constructor(public http:Http){ }
getusersGET(){
return this.http.get('http://jsonplaceholder.typicode.com/users').pipe(
map(res => res.json() ) );
}
that works perfectly good luck !