I am trying to call an API from Angular but am getting this error:
Property 'map' does not exist on type 'Observable<Response>'
The answers from this similar question didn't solve my issue: Angular 2 beta.17: Property 'map' does not exist on type 'Observable<Response>'.
I am using Angular 2.0.0-beta.17.
You need to import the map
operator:
import 'rxjs/add/operator/map'
Or more generally:
import 'rxjs/Rx';
Notice: For versions of RxJS 6.x.x
and above, you will have to use pipeable operators as shown in the code snippet below:
import { map } from 'rxjs/operators';
import { HttpClient } from '@angular/common/http';
// ...
export class MyComponent {
constructor(private http: HttpClient) { }
getItems() {
this.http.get('https://example.com/api/items').pipe(map(data => {})).subscribe(result => {
console.log(result);
});
}
}
This is caused by the RxJS team removing support for using See the breaking changes in RxJS' changelog for more info.
From the changelog:
operators: Pipeable operators must now be imported from rxjs like so:
import { map, filter, switchMap } from 'rxjs/operators';
. No deep imports.