How to use the ng-zorro-antd/core.isPromise function in ng-zorro-antd

To help you get started, we’ve selected a few ng-zorro-antd examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NG-ZORRO / ng-zorro-antd / components / modal / nz-modal.component.ts View on Github external
public onClickOkCancel(type: 'ok' | 'cancel'): void {
    const trigger = { ok: this.nzOnOk, cancel: this.nzOnCancel }[type];
    const loadingKey = { ok: 'nzOkLoading', cancel: 'nzCancelLoading' }[type];
    if (trigger instanceof EventEmitter) {
      trigger.emit(this.getContentComponent());
    } else if (typeof trigger === 'function') {
      const result = trigger(this.getContentComponent());
      const caseClose = (doClose: boolean | void | {}) => doClose !== false && this.close(doClose as R); // Users can return "false" to prevent closing by default
      if (isPromise(result)) {
        this[loadingKey] = true;
        const handleThen = (doClose: boolean | void | {}) => {
          this[loadingKey] = false;
          caseClose(doClose);
        };
        result.then(handleThen).catch(handleThen);
      } else {
        caseClose(result);
      }
    }
  }
github NG-ZORRO / ng-zorro-antd / components / modal / nz-modal.component.ts View on Github external
public onButtonClick(button: ModalButtonOptions): void {
    const result = this.getButtonCallableProp(button, 'onClick'); // Call onClick directly
    if (isPromise(result)) {
      button.loading = true;
      result.then(() => (button.loading = false)).catch(() => (button.loading = false));
    }
  }