Map doesn't exist on Observable<Object> with angular 6.0.0 and rxjs 6.1.0
In rxjs@6
you can use from as standalone function:
import { from } from 'rxjs';
See also migration to rxjs6 guide
https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md#import-paths
UPDATE
You need to switch to pipe syntax, make sure you import all operators used from rxjs/operators. For example:
import { map, filter, catchError, mergeMap } from 'rxjs/operators';
DOCUMENTATION
pipe
is a method on Observable which is used for composing operators
Here is the way how you can use the new method pipe()
in Version 6:
loadProducts() {
return this.http.get("/api/products").
pipe(
map((data: any[]) => {
this.products = data;
return true;
}), catchError( error => {
return throwError( 'Something went wrong!' )
});
)
}
Keep in mind that with Version 6 you should now use catchError
and throwError
instead of:catch
and throw
. Here is the correct import with Version 6:
import { Observable, of, throwError, ...} from "rxjs"
import { map, catchError, ...} from "rxjs/operatros"
You have to change to pipe syntax:
import { Http } from '@angular/http';
import { Injectable } from '@angular/core';
import {map, catchError} from "rxjs/operators";
import { Observable, throwError } from 'rxjs';
list():Observable<any>{
return this.http.get(this.url)
.pipe(
map((e:Response)=> e.json()),
catchError((e:Response)=> throwError(e))
);
}