I'm migrating an Angular 5 app to the latest CLI and Angular 6 RC and all of my Observable imports are broken. I see that Angular 6 changes the way the imports work, but I can't find any definite reference as to how the syntax works.
I had this in 5 and it worked fine:
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/throw';
Now with the new syntax I see that
import { Observable, Subject, throwError} from 'rxjs';
import { map } from 'rxjs/operators';
The first two lines compile, but I can't figure out how to get catch and throw for example. .map() also throws a build error when used in code.
Anybody have a reference to how this is supposed to work?
Run these 2 commands after running
ng update
. This should fix the rxjs imports:References:
Or if you want to keep using version
6.0.0
you donpm i --save rxjs-compat
to add reverse compatibility
Pipes are what is required for operator(s) going forward.
version: rxjs 6.0.1
Example:
From rxjs 5.5,
catch
has been renamed tocatchError
function to avoid name clash.For
throw
you can useErrorObservable
.rxjs 6
Instead of ErrorObservable use throwError.
Also you will now have to pipe the operators instead of directly chaining them to the observable