Skip to content

Instantly share code, notes, and snippets.

@Spittal
Last active August 29, 2015 14:06
Show Gist options
  • Save Spittal/daee094a18354000e831 to your computer and use it in GitHub Desktop.
Save Spittal/daee094a18354000e831 to your computer and use it in GitHub Desktop.
Disabled If Expression Directive for AngularJS
.directive('disabledIf', disabledIf);
function disabledIf() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
var expr = attrs.disabledIf;
scope.$watch(expr, function(val) {
if (val) {
element.attr('disabled', val);
} else {
element.removeAttr('disabled');
}
});
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment