Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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'.

like image 501
Kay Avatar asked May 06 '18 18:05

Kay


2 Answers

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))   ); 
like image 98
Jens Habegger Avatar answered Oct 20 '22 03:10

Jens Habegger


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(...); 
like image 38
Dulanga Heshan Avatar answered Oct 20 '22 04:10

Dulanga Heshan