find and solve || findandsolve.com
Please wait.....

Property map does not exist on type Observable<Response>

I am geting error when trying to call an API from Angular.

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

This is my angular code 

getList(currentPage, pageSize, category, align) {
    return this._http.get(this.appUrl + "api/blog/getBlogList/"
      + currentPage + "/" + pageSize + "/" + category + "/" + align)
      .map((res: Response) => res.json(
      ))
      .catch(this.errorHandler);
  }


Answer


Option 1.

I have solved this problems by given code.

import 'rxjs/add/operator/map'

or

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('example[dot]com/api/items').pipe(map(data => {})).subscribe(result => {
      console.log(result);
    });
  }
}


Option 2.

I had the same issue with Angular 8.0. because I was importing Observable from

import { Observable } from 'rxjs/Observable';
I resolve my problem  like as given below (importing Observable from this path instead).

import { Observable } from 'rxjs';


Option 3.

Just write this command in the VS Code terminal of your project and restart the project.

npm install rxjs-compat

You need to import the map operator by adding this:

import 'rxjs/add/operator/map';


Option 4.

If after importing import 'rxjs/add/operator/map' or import 'rxjs/Rx' too you are getting the same error then restart your visual studio code editor, the error will be resolved.



Mahira  khanna

Mahira khanna

I have the skills you need for you company blog, website, or other content materials

Comments



Report Response