Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Observable.throw replacement in rxjs 5.5.2

Tags:

angular

rxjs

I'm migrating to [email protected] and using lettable operators... I also update Observable static methods. I wonder what is the counterpart of Observable.throw and import 'rxjs/add/observable/throw';.

Should I import ugly _throw?

import { _throw } from 'rxjs/observable/throw';

Or there's a better way. Honestly I liked static methods on Observable, and now it seems that all static creating methods like of, from should be imported from rxjs/observable/<methodName> ?

like image 333
dragonfly Avatar asked Nov 03 '17 14:11

dragonfly


People also ask

What can I use instead of an observable throw?

Observable. if has been replaced by iif() and Observable. throw is now throwError() .


2 Answers

I'm still getting my head round 5.5 but it looks like now instead of importing throw use ErrorObservable.

// import { _throw } from 'rxjs/observable/throw'; import { ErrorObservable } from 'rxjs/observable/ErrorObservable';  ErrorObservable.create('error'); 

From this guide it looks like it has to be _throw to avoid a keyword clash (the rest of the video is good for getting started with 5.5)

like image 101
JayChase Avatar answered Sep 21 '22 23:09

JayChase


In continuation to Mick's answer, in the rxjs version 6 _throw is replaced by throwError

 import {Observable, throwError} from 'rxjs';  

RxJS Migration Guide

like image 43
Jeffrey Nicholson Carré Avatar answered Sep 21 '22 23:09

Jeffrey Nicholson Carré