Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How to create a checkbox in angular using mat-checkbox?


Asked by Kody Meza on Nov 30, 2021 FAQ



In the Angular Checkbox configuration section we have three angular material checkboxes and for each <mat-checkbox> model variables are binded using [(ngModel)] property. As <mat-checkbox> can have only two values true or false i.e., checked or unchecked (indeterminate is only for visual purpose).
Accordingly,
The mat-checkbox is the selector of MatCheckbox directive which is used to create Material design checkbox. The MatCheckbox supports all the functionality of HTML 5 checkbox. A MatCheckbox can be checked, unchecked, indeterminate, or disabled. To work with MatCheckbox, we need to import below module.
Consequently, The angular material library offers an easy solution for creating checkboxes. The mat-checkbox is a profound directive which amplifies the UI control. < mat-checkbox > supports profoundly @angular/forms and works notably with both FormsModule and ReactiveFormsModule. Also mat-checkbox supports an indeterminate state, same as native.
Moreover,
Select Angular Material Pre-built theme, Typography and Animations: In order to create the dynamic list of checkboxes, we need to import and register the MatCheckboxModule and FormsModule API in the app.module.ts file. We need to define the Movies array with some values that we will display to the users.
Indeed,
Other than a Checked, Unchecked or Disabled state, the Indeterminate state of the checkbox can also be applied using Material UI in Angular. For creating Material UI checkboxes in the Angular project we add mat-checkbox component by importing the MatCheckboxModule API. Let’s start creating a Material Checkbox list.