Created
March 24, 2014 15:55
-
-
Save mlegenhausen/9743083 to your computer and use it in GitHub Desktop.
-cs-spinner angular loading directive using angular-promise-tracker and ui-router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('components.spinner-tracker', [ | |
'ajoslin.promise-tracker' | |
]) | |
.directive('csspinner', function (spinnerTracker) { | |
return { | |
scope: { | |
type: '@csspinner' | |
}, | |
link: function (scope, element) { | |
scope.$watch(spinnerTracker.active, function (isActive) { | |
element.toggleClass('csspinner ' + scope.type, isActive); | |
}); | |
} | |
}; | |
}) | |
.factory('spinnerTracker', function (promiseTracker) { | |
return promiseTracker({ | |
activationDelay: 250, | |
minDuration: 750 | |
}); | |
}) | |
.run(function ($rootScope, spinnerTracker) { | |
var deferred; | |
$rootScope.$on('$stateChangeStart', function () { | |
deferred = spinnerTracker.createPromise(); | |
}); | |
$rootScope.$on('$stateChangeSuccess', function () { | |
deferred.resolve(); | |
}); | |
}) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment