Skip to content

Instantly share code, notes, and snippets.

@bjcull
Created July 8, 2015 13:16
Show Gist options
  • Save bjcull/81c409cc5d9c69276eee to your computer and use it in GitHub Desktop.
Save bjcull/81c409cc5d9c69276eee to your computer and use it in GitHub Desktop.
An angular directive for the Ladda loading button. (Requires the jquery ladda plugin).
.directive('loadingButton', [
'$compile', function($compile) {
return {
restrict: 'A',
link: function(scope, element, attr) {
/* attr.style == "data-style" */
if (attr.loadingButtonAnimation && !attr.style) {
element.attr("data-style", attr.loadingButtonAnimation);
} else if (!attr.loadingButtonAnimation && !attr.style) {
element.attr("data-style", "slide-left");
}
if (!element.hasClass("ladda-button")) {
element.addClass("ladda-button");
}
element.ladda();
scope.$watch(attr.loadingButton, function(newValue, oldValue) {
if (newValue) {
$(element).ladda('start');
} else {
$(element).ladda('stop');
}
});
$compile(element.contents())(scope);
}
};
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment