johannesjo / angular2-promise-buttons

Chilled loading buttons for angular2
https://johannesjo.github.io/angular2-promise-buttons/#demo
MIT License
86 stars 28 forks source link

Button not resolving #25

Closed nburnesy closed 4 years ago

nburnesy commented 5 years ago

There are some situations where the button does not resolve, which really confuses me, one example is this:

setPromiseMethod() {
    this.myPromise= new Promise((resolve) => {
      this.dataService.doSomething().then(response => {
        // Success
      }).catch(error => {
        // Errors
      }).finally(() => {
        resolve();
      });
    });
  }

This works fine until I lose network connection, then resolve() is being hit but the button does not stop spinning. What am I missing here?

johannesjo commented 5 years ago

Not 100% sure, but I would assume that a host not being available always leads to a rejected promise. Also Promise.finally was not always available in js, so this might be a problem here. https://github.com/johannesjo/angular2-promise-buttons/blob/f95a5a4f9a69f9f6ab810a7417e02743467a0cda/src/promise-btn.directive.ts#L180-L187

nburnesy commented 5 years ago

The finally bit doesn't seem to be relevant, same thing happens with a resolve() in the then and catch blocks.

Shouldn't the button stop spinning on reject? I'm reproducing this issue by clicking the offline checkbox in the chrome network tab.

Also, I can avoid it by wrapping the contents of the promise in setTimeout(0)

johannesjo commented 5 years ago

It should. That's what the catch is for. And in the examples it also does: https://johannesjo.github.io/angular2-promise-buttons/#demo

Could you maybe provide a more complete example (ideally jsbin, plunkr, etc.?