how to get checkbox value in angular?
you need to use change
event
<mat-checkbox (change)="checkCheckBoxvalue($event)">Check me!</mat-checkbox>
checkCheckBoxvalue(event){
console.log(event.checked)
}
Working Example
other ways -
You can use two way data binding for the same like mentioned below -
<input type="checkbox" name="myData" [(ngModel)]="isChecked">
You can use a local variable as well and fetch the value in controller side like below -
<input type="checkbox" name="myData" #myCheckbox> @ViewChild('myCheckbox') myCheckbox; console.log(myCheckbox, 'Value of checkbox');
Other way is you can use formControl for the same, either it can be model-driven form or template-driven form.
Use change event.target.checked.
<mat-checkbox (change)="checkCheckBoxvalue($event)">Check me!</mat-checkbox>
checkCheckBoxvalue(event){
console.log(event.target.checked)
}
bind an [ngModel] to the checkbox
<input type="checkbox" name="checkbox" [(ngModel)]="isChecked">
const isChecked : boolean;