dist/angular-promise-buttons.js
function initPromiseWatcher(watchExpressionForPromise, btnEl) {
          // watch promise to resolve or fail
          scope.$watch(watchExpressionForPromise, function (mVal) {
            minDurationTimeoutDone = false;
            promiseDone = false;

            // create timeout if option is set
            if (cfg.minDuration) {
              minDurationTimeout = $timeout(function () {
                minDurationTimeoutDone = true;
                handleLoadingFinished(btnEl);
              }, cfg.minDuration);
            }

            // for regular promises
            if (mVal && mVal.then) {
              initLoadingState(btnEl);

              // angular promise
              if (mVal.finally) {
                mVal.finally(function () {
                  promiseDone = true;
                  handleLoadingFinished(btnEl);
                });
              }
              // ES6 promises
              else {
                mVal.then(function () {
                    promiseDone = true;
                    handleLoadingFinished(btnEl);
                  })
                  .catch(function () {
                    promiseDone = true;
                    handleLoadingFinished(btnEl);
                  });
              }

            }
            // for $resource
            else if (mVal && mVal.$promise) {
              initLoadingState(btnEl);
              mVal.$promise.finally(function () {
                promiseDone = true;
                handleLoadingFinished(btnEl);
              });
            }
          });
        }
function initPromiseWatcher(watchExpressionForPromise, btnEl) {
          // watch promise to resolve or fail
          scope.$watch(watchExpressionForPromise, function (mVal) {
            minDurationTimeoutDone = false;
            promiseDone = false;

            // create timeout if option is set
            if (cfg.minDuration) {
              minDurationTimeout = $timeout(function () {
                minDurationTimeoutDone = true;
                handleLoadingFinished(btnEl);
              }, cfg.minDuration);
            }

            // for regular promises
            if (mVal && mVal.then) {
              initLoadingState(btnEl);

              // angular promise
              if (mVal.finally) {
                mVal.finally(function () {
                  promiseDone = true;
                  handleLoadingFinished(btnEl);
                });
              }
              // ES6 promises
              else {
                mVal.then(function () {
                    promiseDone = true;
                    handleLoadingFinished(btnEl);
                  })
                  .catch(function () {
                    promiseDone = true;
                    handleLoadingFinished(btnEl);
                  });
              }

            }
            // for $resource
            else if (mVal && mVal.$promise) {
              initLoadingState(btnEl);
              mVal.$promise.finally(function () {
                promiseDone = true;
                handleLoadingFinished(btnEl);
              });
            }
          });
        }
function initPromiseWatcher ( watchExpressionForPromise , btnEl ) { // watch promise to resolve or fail scope . $watch ( watchExpressionForPromise , function ( mVal ) { minDurationTimeoutDone = false ; promiseDone = false ; // create timeout if option is set if ( cfg . minDuration ) { minDurationTimeout = $timeout ( function ( ) { minDurationTimeoutDone = true ; handleLoadingFinished ( btnEl ) ; } , cfg . minDuration ) ; } // for regular promises if ( mVal && mVal . then ) { initLoadingState ( btnEl ) ; // angular promise if ( mVal . finally ) { mVal . finally ( function ( ) { promiseDone = true ; handleLoadingFinished ( btnEl ) ; } ) ; } // ES6 promises else { mVal . then ( function ( ) { promiseDone = true ; handleLoadingFinished ( btnEl ) ; } ) . catch ( function ( ) { promiseDone = true ; handleLoadingFinished ( btnEl ) ; } ) ; } } // for $resource else if ( mVal && mVal . $promise ) { initLoadingState ( btnEl ) ; mVal . $promise . finally ( function ( ) { promiseDone = true ; handleLoadingFinished ( btnEl ) ; } ) ; } } ) ; }
Initializes a watcher for the promise. Also takes
cfg.minDuration into account if given.
@param {Function}watchExpressionForPromise
@param {Object}btnEl
Initializes a watcher for the promise . Also takes cfg . minDuration into account if given .