1

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

3
  • 2
    Can you share what you have done? Commented Apr 25, 2018 at 18:59
  • Bind the checked property of checkbox and disabled property of input to a componentProperty[defaults to false], so when checkbox is checked componentProperty will become true which will enable input if you use !componentProperty with input's disabled property Commented Apr 25, 2018 at 19:14
  • @faizan any example references ? Commented Apr 25, 2018 at 20:09

1 Answer 1

5

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" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.