CheckBox Overview
The CheckBox enables you to style input type="checkbox"
elements.
Basic Usage
The CheckBox lets the user toggle between checked and unchecked states. All regular input type="checkbox"
HTML attributes and Angular bindings are applicable.
Associating with Labels
The CheckBox can be associated with an HTML label
element like the regular <input type="checkbox">
or with the Label component
.
Forms Support
You can use the CheckBox in template-driven or reactive forms.
Template Forms
The template-driven forms enable you to bind the CheckBox to the forms model by using the ngModel
directive.
The following example demonstrates how to use the CheckBox in a template-driven form.
Reactive Forms
The FormGroup
provides a way to render reactive forms. For more details, refer to the Angular Documentation.
The following example demonstrates how to use the CheckBox in a reactive form.
FormField Association
The following example demonstrates how to use the CheckBox within a FormField
component and provide hint and error messages.
Required CheckBox
You can make the CheckBox required.
To do so use one of the following:
required
attribute- Angular property binding syntax
- Angular Form Validator
Indeterminate State
The CheckBox can display an indeterminate
state when the respective property is set to true
.
The indeterminate
state is independent of the checked
state and upon user interaction the current checked
state will be displayed.
Disabled CheckBox
By default, the CheckBox is enabled.
To disable user interaction with the element, use the disabled
attribute or Angular property binding.