Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

How I can disabled input inside Angular?


How I can disabled input inside Angular?


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (2)


Thanks a ton to get writing this sort of superb posting! I uncovered your web blog ideal for this demands. Contained in the grapefruit excellent plus handy discussions. Keep up to date favorable deliver the results! halloween panties



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.


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(