Skip to content

Instantly share code, notes, and snippets.

@billyxs
Last active October 14, 2015 17:55
Show Gist options
  • Save billyxs/b4ce387bcd4195605d0a to your computer and use it in GitHub Desktop.
Save billyxs/b4ce387bcd4195605d0a to your computer and use it in GitHub Desktop.
Angular directive for a button that shows an animation when "processing". Good for when a form is being posted, and the user is waiting for a result
// Requires font-awesome for spinning functionality
angular.module('buttonUtils')
.directive('processingButton', function() {
return {
scope: {
buttonText:"@",
buttonProcessing: "="
},
link: function(scope, element, attrs) {
var $span = element.find('span');
scope.$watch('buttonProcessing', function(val) {
console.log('watching', val);
if (val) {
$span.addClass('fa-pulse fa-spinner');
} else {
$span.removeClass('fa-pulse fa-spinner');
}
});
},
template: ['<button type="submit" class="btn btn-primary submit-button">',
'<span class="fa " class="form-control">',
'</span>',
' {{buttonText}}',
'</button>'
].join('')
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment