Skip to content

Instantly share code, notes, and snippets.

@Yukilas
Created October 30, 2012 09:42
Show Gist options
  • Save Yukilas/3979293 to your computer and use it in GitHub Desktop.
Save Yukilas/3979293 to your computer and use it in GitHub Desktop.
AngularJS - Button loading directive
/*
``btn-loading`` attribute.
This attribute will update the button state using Twitter Bootstrap button plugin and
according the attribute value.
The attribute value should be a scope variable.
If the variable is ``true`` the button will have the ``loading`` state.
If the variable is ``false`` the button will be reset and displayed normaly.
Usage:
<button class="btn" btn-loading="is_loading" data-loading-text="Save in progess ..">Save</button>
*/
app.directive("btnLoading", function(){
return function(scope, element, attrs){
scope.$watch(function(){ return scope.$eval(attrs.btnLoading); }, function(loading){
if(loading) return element.button("loading");
element.button("reset");
});
}
});
@elsh32
Copy link

elsh32 commented Aug 19, 2017

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment