How I can disabled input inside Angular?
How I can disabled input inside Angular?
Replies (1)
Hi Thy Nguyen
To disable an input in Angular, you can use the disabled attribute binding. Here's how you can do it:
If you are using template-driven forms, you can use the ngModel directive along with the disabled attribute:
<input type="text" [(ngModel)]="myValue" [disabled]="isDisabled" /> In your component, you would have a property isDisabled that you can toggle to enable or disable the input:
isDisabled = false; Reactive Forms:
If you are using reactive forms, you can disable the form control directly:
myForm.get("myControl").disable(); And to enable it:
myForm.get("myControl").enable(); Replace 'myControl' with the name of your form control.
Remember to import FormsModule for template-driven forms or ReactiveFormsModule for reactive forms in your Angular module.