I'm trying to implement a loader while the data is fetching form firebase.
this is my code:
this.handler.loadingPresent();
this.rooms = this.locationProvider.fetchRooms();
this.rooms.do(()=>{
this.handler.loadingDismiss();
});
The rooms FirebaseListObservable
is subscribed in the component file using the | async pipe.
So why the .do()
operator is not working ?!
Thanks
The operator doesn't modify the observable it's called on. It creates and returns a new observable. So the code should be
this.rooms = this.locationProvider.fetchRooms();
this.rooms = this.rooms.do(() => {
this.handler.loadingDismiss();
});
Or, simpler and more idiomatic:
this.rooms = this.locationProvider.fetchRooms()
.do(() => this.handler.loadingDismiss());
Note that your "loading" will only be dismissed if there is no error when fetching the rooms. If you want your loading to dismiss no matter what, you should use the finally
operator rather than do
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments