Menu items in Angular. Steps to implement Menu items in Angular applications. Step 1: Import Angular material Menu module. We can import material menu module (MatMenuModule) in our components ts file or app.module.ts file or some common material module which can be used across the application as explained in angular material tutorial. Using mat-form-field input matInput and are used inside mat-form-field. It applies common underline, floating label and hint messages etc. Mat-form-field is used with input matInput as given below. Using mat-label. In this Angular 9 tutorial, we’ll create a Multi checkbox list using the Material UI library’s mat-checkbox component. This checkbox list can be checked and unchecked by clicking a master checkbox which will also display indeterminate state.
Set the disabled attribute to the result of an expression and Angular will disable / enable the element for you as needed.
Disable an HTML Element – Example # 1
2 4 6 8 10 | selector:'home', }) count:number=0; } |
In example # 1, we have our component. There are two properties we are interested in: count and buttonDisabled. We will leverage these in our template.
Disable an HTML Element – Example # 2
Mat Input Set 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.
Important note: these two buttons are for demonstration purposes only. The focus of this article is the Angular [disabled] attribute.
Mat Input Set Disabled Windows
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
If you want to download the example code, visit this Github page, and then follow the instructions: bit.ly/kcv-angular-disabled-attribute