I am trying to incorporate a checkbox in Angular where if it is enabled, the event.target.checked value is true, and if it is disabled, the event.target.checked value is false. When clicking the checkbox, I need to call a function where I want to pass the event and value. I am not sure if passing event and values as arguments is possible in Angular or not?
XYZ.component.html
<form [formGroup]="XYZGroup">
<div class="form-group row">
<div class="col-md-4 text-left" id="email">
<label><input type="checkbox" formcontrolName="emailData" [checked]="Data.email=='enabled'" (change)="checkEmail($event.target.checked, value)">
<b>Email</b></label>
</div>
</div>
<form>
<button (click)="submit()">Submit</button>
XYZ.component.ts
ngOnInit(){
this.XYZGroup = this.fb.group({
emailData: new FormControl(''),)}
}
checkEmail(e, value) {
if (e) {
value = "enabled"
}
else {
value = 'disabled'
}
return value;
}
submit(){
let emailDataValue = this.checkEmail(event, this.XYZform.value.emailData)
body:{
"email": this.emailDataValue
}
}
My question is if 'this.XYZform.value.emailData = disabled' means I need to uncheck the checkbox, and if 'this.XYZform.value.emailData = enabled' means I need to check the checkbox