7

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.

Community
  • 1
  • 1
Mohan Gopi
  • 7,606
  • 17
  • 66
  • 117
  • 1
    Possible duplicate of [How to return an empty observable in rxjs](https://stackoverflow.com/questions/38548407/how-to-return-an-empty-observable-in-rxjs) – Murhaf Sousli Dec 02 '17 at 01:47
  • please read my question i have mentioned your question and asked my question diff from yours @murhaf – Mohan Gopi Dec 02 '17 at 03:03

2 Answers2

12

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();
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
0

In angular 2 you can return empty observable by using this :

import {EmptyObservable} from 'rxjs/EmptyObservable';
    return new EmptyObservable();