Skip to content

Instantly share code, notes, and snippets.

@d33d33
Created December 8, 2013 23:36
Show Gist options
  • Save d33d33/7865188 to your computer and use it in GitHub Desktop.
Save d33d33/7865188 to your computer and use it in GitHub Desktop.
AngularJS directive for bootstrap-switch
<div class="switch" bootstrap-switch state="user.isAdmin">
<input type="checkbox" />
</div>
module.directive('bootstrapSwitch', function() {
return {
restrict:'A',
scope: {
state: '='
},
link: function(scope, element, attrs) {
$(element).bootstrapSwitch();
$(element).bootstrapSwitch('setState', attrs.bootstrapSwitch);
$(element).on('switch-change', function (e, data) {
scope.$apply(function(){
scope.state = data.value;
});
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment