Skip to content

Instantly share code, notes, and snippets.

@adrianorsouza
Forked from bjcull/bootstrapSwitch.js
Created December 2, 2015 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrianorsouza/9c9ef002143fd365fab7 to your computer and use it in GitHub Desktop.
Save adrianorsouza/9c9ef002143fd365fab7 to your computer and use it in GitHub Desktop.
Angular directive for bootstrap-switch | http://www.bootstrap-switch.org/
.directive('bootstrapSwitch', [
function() {
return {
restrict: 'A',
require: '?ngModel',
link: function(scope, element, attrs, ngModel) {
element.bootstrapSwitch();
element.on('switchChange.bootstrapSwitch', function(event, state) {
if (ngModel) {
scope.$apply(function() {
ngModel.$setViewValue(state);
});
}
});
scope.$watch(attrs.ngModel, function(newValue, oldValue) {
if (newValue) {
element.bootstrapSwitch('state', true, true);
} else {
element.bootstrapSwitch('state', false, true);
}
});
}
};
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment