Kay
Kay

Reputation: 19660

Angular 5 to 6 Upgrade: Property 'map' does not exist on type Observable

Ive upgraded my angular application from version 5 to 6 and im getting this error from the following code.

  const request = this.evidenceService.get().map((res) => res.data)
                .catch(error => Observable.of(null));

Property 'map' does not exist on type 'Observable'.

Upvotes: 22

Views: 54684

Answers (5)

nakli_batman
nakli_batman

Reputation: 741

If anyone is facing error that json is not supported while writing the following,

.pipe(map((res) => res.json()))

Then I think in later version of angular it is safe to remove .json . and It will work Perfectly.

Upvotes: 0

Jens Habegger
Jens Habegger

Reputation: 5446

Operator chaining has been transitioned to the use of .pipe() in RXJS v6, you should follow the recommended migration path for RXJS. Additionally, the catch operator has been renamed to catchError.

Here is how it should be done now:

const request = this.evidenceService.get().pipe(
    map((res) => res.data)),
    catchError(error => Observable.of(null))
  );

Upvotes: 61

Pullat Junaid
Pullat Junaid

Reputation: 3384

Use

.pipe(map((res) => res.data))

instead of

.map((res) => res.data)

Upvotes: 2

Greko2015 GuFn
Greko2015 GuFn

Reputation: 589

This solved my problem here is the code:

import { map } from "rxjs/operators";

**********************************************Example**Below**************************************

getPosts(){
this.http.get('http://jsonplaceholder.typicode.com/posts')
.pipe(map(res => res.json()));
}
}

Upvotes: 7

Dulanga Heshan
Dulanga Heshan

Reputation: 1425

according to https://www.academind.com/learn/javascript/rxjs-6-what-changed/

in past

import 'rxjs/add/operator/map'

myObservable
  .map(data => data * 2)
  .subscribe(...);

now

import { map } from 'rxjs/operators';

myObservable
  .pipe(map(data => data * 2))
  .subscribe(...);

Upvotes: 31

Related Questions