Skip to content

Instantly share code, notes, and snippets.

@mlegenhausen
Created March 24, 2014 15:55
Show Gist options
  • Save mlegenhausen/9743083 to your computer and use it in GitHub Desktop.
Save mlegenhausen/9743083 to your computer and use it in GitHub Desktop.
-cs-spinner angular loading directive using angular-promise-tracker and ui-router
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