Property ‘map’ Does Not Exist on Type ‘observable‘

You need to import the map operator:

[php]import ‘rxjs/add/operator/map'[/php]

Or more generally:

[php]import ‘rxjs/Rx’;[/php]


Notice: For versions of RxJS 6.x.x and above, you will have to use pipeable operators as shown in the code snippet below:

[php]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);
});
}
}[/php]

 

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.

Leave a Comment