Skip to content

Instantly share code, notes, and snippets.

@DavidVotrubec
Last active August 29, 2015 13:56
Show Gist options
  • Save DavidVotrubec/9251420 to your computer and use it in GitHub Desktop.
Save DavidVotrubec/9251420 to your computer and use it in GitHub Desktop.
sg-readonly directive (written in TypeScript). Disables all nested fields when condition is met.
Module.directive("sgReadonly", [() => {
function toggleDisableAttr(fields:any[], isDisabled:boolean) {
_.each(fields, (f: any) => angular.element(f).prop('disabled', isDisabled));
}
return {
restrict: "A",
scope: {
isReadonly: '=sgReadonly',
},
link: (scope, elm, attrs, ctrl) => {
var fields = elm.find('[ng-model]');
scope.$watch('isReadonly', (value: boolean)=> {
toggleDisableAttr(fields, value);
});
}
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment