how to return an empty observable
14,059
Observable.of()
should work for your case:
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/of';
// or import {Observable} from 'rxjs/Rx';
return Observable.of();
or
import {EmptyObservable} from 'rxjs/EmptyObservable';
return new EmptyObservable();
Related videos on Youtube
Author by
Mohan Gopi
Each and every end of the day thinking what i have learned today. And Improving my self daily as developer.
Updated on June 04, 2022Comments
-
Mohan Gopi almost 2 years
according to this answer How to return an empty observable in rxjs i have tried all of it but it did not work for me
here is my code
post(url):Observalbe<any>{ if(this.holder.nullConnection()){ //checking internet connection //return empty observalbe return Observable.empty() ; }else{ return this.http.post(this.configurator.restServerBaseUrl+url,data) .map((result:Response)=> { return result.json() }) } }
i have tried almost all the answers as per the stack question you can see above any help to return an empty obserable.
-
Mohan Gopi over 6 yearsplease read my question i have mentioned your question and asked my question diff from yours @murhaf
-
Murhaf SousliPossible duplicate of How to return an empty observable in rxjs
-
-
Mohan Gopi over 7 yearsi tried both as i am using visual studio and my editor is showing error on
of()
do we have to import anything like EmptyObservable -
Mohan Gopi over 7 yearsas you can see my else part is working fine only i am struggling to retrun an empty observable
-
Suraj Rao over 7 yearsu have to import the of operator
-
Mohan Gopi over 7 yearsit is saying that cannot find name of() like that
-
Suraj Rao over 7 yearsimport 'rxjs/add/observable/of';
-
Mohan Gopi over 7 years@GünterZöchbauer [ts] Property 'of' does not exist on type 'typeof Observable'. this is the error