##Checkbox
The Ignite UI for Angular Checkbox component is a selection control that allows users to make a binary choice for a certain condition. It behaves similarly to the native browser checkbox.
Checkbox Demo
Usage
At its core, the checkbox component allows for a choice between selected/unselected state. The default styling is done according to the selection controls specification as per the Material Design guidelines.
To get started with the Ignite UI for Angular Checkbox import the IgxCheckboxModule
in the app.module.ts file:
// app.module.ts
...
import { IgxCheckboxModule } from 'igniteui-angular';
@NgModule({
...
imports: [..., IgxCheckboxModule],
...
})
export class AppModule {}
To get a simple checkbox, add the following code inside the component template:
<igx-checkbox [checked]="true">
simple checkbox
</igx-checkbox>
If all went well, you should see something like the following in the browser:
Checkbox properties
Let's enhance the code above by binding the checkbox properties to some data. Say, we have an array of task objects, each having two properties: description and done. You can bind the checkbox component checked
property to the underlying task object done property. Analogically, you can bind the value
property to description.
Optionally, you can also bind the change
event and add some custom logic in the provided event handler method.
// tasks.component.ts
...
public tasks = [
{ done: true, description: 'Research' },
{ done: true, description: 'Implement' },
{ done: false, description: 'Test' },
];
...
statusChanged()
{
// event handler logic
}
Enhance the component template by adding a checkbox for each task and then setting the corresponding property bindings:
<!--tasks.component.html-->
<igx-checkbox *ngFor="let task of tasks" [checked]="task.done">
{{ task.description }}
</igx-checkbox>
The final result would be something like that:
API References
Additional Resources
Our community is active and always welcoming to new ideas.