how could you achieve in Angular 4 that when you register in a checkbox save an \"A\" or \"B\" value. As much as I try, he is only sending me true or false, I hope someone c
changed = (evt) => {
this.isChecked = evt.target.checked;
}
<input type="checkbox" [checked]="checkbox" (change)="changed($event)" id="no"/>
Another approach is to use ngModelChange
:
Template:
<input type="checkbox" ngModel (ngModelChange)="onChecked(obj, $event)" />
Controller:
onChecked(obj: any, isChecked: boolean){
console.log(obj, isChecked); // {}, true || false
}
I prefer this method because here you get the relevant object and true
/false
values of a checkbox.
Inside your component class:
checkValue(event: any) {
this.userForm.patchValue({
state: event
})
}
Now in controls you have value A or B