I have a text box which is disabled using simple disabled html tag. I need to enable it when I click checkbox, again I need to disable it when i uncheck the checkbox.
-
Possible duplicate of stackoverflow.com/questions/62277274/…Ajay Jangra– Ajay Jangra2022-06-03 11:31:28 +00:00Commented Jun 3, 2022 at 11:31
-
1Does this answer your question? Angular: How do I enable and disable a textbox by clicking a checkbox?Roy– Roy2022-06-03 11:39:49 +00:00Commented Jun 3, 2022 at 11:39
Add a comment
|
2 Answers
checkValue = false;
InputDisabled = true;
ChangeEvent(){
if(this.checkValue)
{
this.InputDisabled = false;
} else
{
this.InputDisabled = true;
}
}
<label for="">Add text to destination filename?</label>
<input class="form-check-input" type="checkbox" [(ngModel)]="checkValue" (change)="ChangeEvent()" id="flexCheckDefault">
<label for="">Text</label>
<input type="text" style="width: 100px;" [disabled]="InputDisabled">
1 Comment
Ethan
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
You can use ngModels in Angular to see enable/disable the button. Also, renember that you can need to create the variable of the ngModel on your AppComponent.
I create a test project for you: https://stackblitz.com/edit/angular-ivy-npvbz5?file=src/app/app.component.html