how to return an empty observable

后端 未结 2 820
耶瑟儿~
耶瑟儿~ 2021-01-18 13:51

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):Obser         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-18 14:21

    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();
    

提交回复
热议问题