Angular Material Checkbox

The <mat-checkbox> is used as an enhanced checkbox with content design styling and animation features. It provides precise functionality as a basic <input type = "checkbox"> content design enhanced with styling and animations.

The checkbox label is provided as the content of the <mat-checkbox> element. The brand is posted by setting the Label Status property to 'Before' or 'After' before or after the checkbox. If you do not want the label to appear next to the checkbox, you can use aria-label or aria-label to specify a suitable label.

Use with @angular/forms

<mat-checkbox> is compatible with @ angular / forms and supports both FormsModule and ReactiveFormsMinule.

Intermediate state

<mat-checkbox> supports an indefinite state <input type = "checkbox">. Although the indefinite property of the checkbox is correct, it will render it as undetermined regardless of the checked value.

Click on action config

When the user clicks the matte-checkbox, the default behavior toggles the checked value and sets Uncertain to False. It provides functionality similar to a native <input type = "checkbox"> enhanced with <mat- <mat-checkbox> material design styling and animations.

The possible values are:

noop

Do not change the indefinite value. Developers have the power to implement customized click actions.

check

Ignore the indefinite value and toggle the checked value of the checkbox. If the checkbox is in an indefinite state then the checkbox will display as an indefinite checkbox of the checked value.

check-indeterminate

When the user clicks the mat-checkbox, set Uncertain to False.

Theming

The color of <mat-checkbox> will be changed using the color property. Checkboxes use the theme's accent color by default. It can be adjusted to 'Primary' or 'Warning'.

Accessibility

<mat-checkbox> uses internal <input type = "checkbox"> to provide an accessible experience. It receives the internal checkbox focus and is automatically labelled the text content of the <mat-checkbox> element.

Createing Angular Application

Follow the steps to update the Angular application:

  1. Create a project with a content application.
  2. Modify module.ts, app.component.ts, app.component.css and app.component.html. Keep the remaining files unchanged.
  3. Compile and run the application.

Let's see an example.

The file is a modified module descriptor.

app.module.ts

app.component.html

app.component.css

app.component.ts

Output:

Angular Material Checkbox

Previously, we have created three check boxes using mat-checkboxes and tied them using ngModel with variables. After that, we have created another checkbox and tied its various attributes with variables in the .ts file.

Let's see another example to create check boxes.

app.component.html

app.module.ts

app.component.css:

Output:

Angular Material Checkbox

When we click on the check boxes, the boxes fill with color and a small check sign appears to it.

Angular Material Checkbox




Latest Courses