do rxjs operator is not working with ionic2

Khaled Ramadan

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

JB Nizet

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.

edited at
0

Comments

0 comments
Login to comment

Related