From 02fa8782f82e8abbd7e82ba10beecb94a319d35a Mon Sep 17 00:00:00 2001 From: Thompson Sanjoto Date: Wed, 4 Oct 2017 16:49:21 -0700 Subject: [PATCH] broadcast the complete event after the animation finishes --- src/loading-bar.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/loading-bar.js b/src/loading-bar.js index 44e092a..ada8f81 100644 --- a/src/loading-bar.js +++ b/src/loading-bar.js @@ -171,6 +171,7 @@ angular.module('cfp.loadingBar', []) this.$get = ['$injector', '$document', '$timeout', '$rootScope', function ($injector, $document, $timeout, $rootScope) { var $animate; + var $q; var $parentSelector = this.parentSelector, loadingBarContainer = angular.element(this.loadingBarTemplate), loadingBar = loadingBarContainer.find('div').eq(0), @@ -193,6 +194,9 @@ angular.module('cfp.loadingBar', []) if (!$animate) { $animate = $injector.get('$animate'); } + if (!$q) { + $q = $injector.get('$q'); + } $timeout.cancel(completeTimeout); @@ -294,24 +298,30 @@ angular.module('cfp.loadingBar', []) function _completeAnimation() { status = 0; started = false; + $rootScope.$broadcast('cfpLoadingBar:completed'); } function _complete() { if (!$animate) { $animate = $injector.get('$animate'); } + if (!$q) { + $q = $injector.get('$q'); + } _set(1); $timeout.cancel(completeTimeout); // Attempt to aggregate any start/complete calls within 500ms: completeTimeout = $timeout(function() { - var promise = $animate.leave(loadingBarContainer, _completeAnimation); - if (promise && promise.then) { - promise.then(_completeAnimation); - } - $animate.leave(spinner); - $rootScope.$broadcast('cfpLoadingBar:completed'); + var promiseBar = $animate.leave(loadingBarContainer); + var promiseSpinner = $animate.leave(spinner); + + $q.all([promiseBar, promiseSpinner]) + .then(function() { + _completeAnimation(); + }); + }, 500); }