Search code examples
angularangular4-forms

Enable input filed when checkbox is checked in Angular 4


By default the input fields are disabled, I should be enable the fields once the check box is checked. Any idea in angular 4 ?


Solution

  • Not sure if I understand the question here but make sure your check box is not bind a model which is already set to false (or default bool)

    If you are simply trying to enable the check box when the checkbox is checked, you can do the following:

    export class AppComponent {
        isDisabled = true;
        triggerSomeEvent() {
            this.isDisabled = !this.isDisabled;
            return;
        }
    }
    

    and your HTML:

    <input type="checkbox" name="myChk" id="myChk" (change)="triggerSomeEvent()" />
    <input type="text" name="myTxt" id="myTxt" value="" [disabled]="isDisabled" />