Last active
April 18, 2019 21:15
-
-
Save sliceofbytes/b21a0b61261ebbc5fdab47cad8342e5d to your computer and use it in GitHub Desktop.
Disable Reactive Forms Directive
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
// 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