function finished(ev) {
          if (ev && ev.target !== element[0]) return;

          if (ev) $timeout.cancel(timer);
          element.off($mdConstant.CSS.TRANSITIONEND, finished);

          // Never reject since ngAnimate may cause timeouts due missed transitionEnd events
          resolve();
        }
Upon timeout or transitionEnd, reject or resolve (respectively) this promise.
NOTE: Make sure this transitionEnd didn't bubble up from a child