Last active
August 29, 2015 13:56
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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