[Solved] Property 'map' does not exist on type 'Observable<Response>'

Article Mohaimen Khalid

Problem: I am trying to call an API from Angular but am getting this error:

Error: Property 'map' does not exist on type 'Observable'

I found solutions but this solutions didn't solve my issue.

Solutions:

You need to import the map operator:

import { map } from 'rxjs/operators';
Change

import 'rxjs/add/operator/map';
To

import { map } from 'rxjs/operators';

If you are using angular below v5/6 you have to add this -

import 'rxjs/add/operator/map';

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

export class MyComponent {
    constructor(private http: HttpClient) { }
      getItems() {
      this.http.get('https://example.com/api/items').pipe(map(data => {}))
        .subscribe(result => {
          console.log(result);
        });
      }
  }