Skip to content

Instantly share code, notes, and snippets.

@daanl
Created November 21, 2013 10:36
Show Gist options
  • Save daanl/7579441 to your computer and use it in GitHub Desktop.
Save daanl/7579441 to your computer and use it in GitHub Desktop.
app.directive('toggleButton', [function () {
return {
restrict: 'E',
templateUrl: '/App/views/shared/directives/toggle.button.html',
replace: true,
scope: {
model: '=',
ngDisabled: '='
},
link: function ($scope, $element, attrs) {
$element.bootstrapSwitch();
$element.bootstrapSwitch('setState', $scope.model);
$element.on('switch-change', function (e, data) {
var value = data.value;
$scope.model = value;
});
$scope.$watch('ngDisabled', function (newValue, old) {
if (newValue === old) {
return;
}
$element.bootstrapSwitch('setActive', !newValue);
}, true);
}
};
}]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment