Errors importing from rxjs, v5 to v6 changes needed.

The example gave:

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/throw';

but I had to change it to:

import { Observable } from 'rxjs';
import { map, catchError } from 'rxjs/operators';

This is because of updates moving from RxJS v5.x to v6 in August 2018. In my package.json file, I’m using  “rxjs”: “~6.3.3”

The previous coding style of chaining operators has been replaced by piping the result of one operator to another. Pipeable operators were added in version 5.5.

public isLoggedIn(username: string, password: string): Observable<boolean> {
    let headers = new Headers({'Content-Type':'X-custom'});
    let option = new RequestOptions({headers: headers});
    return this.http.get('./assets/login.json', option).pipe(
        map((res: Response) => {
            return res.json().username === username &&
                   res.json().password === password;
        }),
        catchError((error: any) => {
            return Observable.throw(error.statusText)
        }));
}

https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md

Leave a comment