Skip to content

Instantly share code, notes, and snippets.

@sliceofbytes
Last active April 18, 2019 21:15
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 sliceofbytes/b21a0b61261ebbc5fdab47cad8342e5d to your computer and use it in GitHub Desktop.
Save sliceofbytes/b21a0b61261ebbc5fdab47cad8342e5d to your computer and use it in GitHub Desktop.
Disable Reactive Forms Directive
// https://netbasal.com/disabling-form-controls-when-working-with-reactive-forms-in-angular-549dd7b42110
import { NgControl } from '@angular/forms';
@Directive({
selector: '[disableControl]'
})
export class DisableControlDirective {
@Input() set disableControl( condition : boolean ) {
const action = condition ? 'disable' : 'enable';
this.ngControl.control[action]();
}
constructor( private ngControl : NgControl ) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment