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 can help me.
registry.component.ts
this.userForm = new FormGroup({
state: new FormControl('',),
});
registry.component.html
<div class="form-group">
<label>State</label>
<input type="checkbox" [(ngModel)]="isChecked" (change)="checkValue(isChecked?'A':'B')" formControlName="state"/>
</div>
<pre>{{userForm.value | json}}</pre>
That way I can get the console to show the value I want (A or B) but in the JSON is still true or false.
This it what you are looking for:
Inside your class:
Also include FormsModule in
app.module.ts
to make ngModel work !Hope it Helps!
Another approach is to use
ngModelChange
:Template:
Controller:
I prefer this method because here you get the relevant object and
true
/false
values of a checkbox.I am guessing that this is what something you are trying to achieve.
Give a try on this,
Template
Ts File
You can use this:
And on your ts file,
Here, record is the model for current row and status is boolean value.