Mat Input Set Disabled

Set the disabled attribute to the result of an expression and Angular will disable / enable the element for you as needed.

Mat

Disable an HTML Element – Example # 1

Disabled
2
4
6
8
10
12
14
<button>
</button>
<!--enable the button-->
Enable Button
<button disabled='disabled'>
</button>

In example # 2, we have our template. There are three buttons. The first two buttons toggle each other. That is to say, when the first button is clicked it is destroyed, and the second button is created. Conversely, when the second button is clicked, it is destroyed and the first button is created. All of this happens because each button has an ngIf attribute. That attribute is watching for the value of the buttonDisabled property. Also, each button has a click attribute. In each case, clicking the button updates the value of the buttonDisabled property.

Mat Input Set Disabled

Important note: these two buttons are for demonstration purposes only. The focus of this article is the Angular [disabled] attribute.

Next, take a look at the third button. It has a disabled attribute. That attribute is set to toggle based on the buttonDisabled property. So when the buttonDisabled property is true, that third button is disabled. And when the buttonDisabled property is false, the third button is not disabled.

Video Example Code

Mat Input Set Disabled File

If you want to download the example code, visit this Github page, and then follow the instructions: bit.ly/kcv-angular-disabled-attribute

Comments are closed.