How can I change the boolean value if the checkbox is checked?


gmark11

I want to change a boolean value in a component file with a simple checkbox. It should remain false if not checked, otherwise it should be true.

Element:

export class UsersComponent {
  public Personal: boolean = false;
}

HTML:

<label>
    <input type="checkbox" name="Personal" [(ngModel)]="Personal"/>
    Personal
</label>
Shlok Nangia

Since you added a 2-way binding in your html [(ngModel)]="Personal", it should be automatically assigned

inspection passed

<label>
    <input type="checkbox" name="Personal" [(ngModel)]="Personal"/>
    {{Personal}}
</label>

Related


How can I change the value of the checkbox if checked?

or I want to change the value of checkboxes when I select them from 0-1 This is what I tried HTML <input type="checkbox" name="Semi Annual" id="1" value="0"> Semi Annual <br> <input type="checkbox" name="Quaterly" id="2" value="0">

How can I change the value of the checkbox if checked?

or I want to change the value of checkboxes when I select them from 0-1 This is what I tried HTML <input type="checkbox" name="Semi Annual" id="1" value="0"> Semi Annual <br> <input type="checkbox" name="Quaterly" id="2" value="0">

How can I change the checked state to uncheck this Checkbox case?

Oscar Rojas Murillo Please help me here...I have a list of checkboxes with "isChecked" value in DB, but I don't know how to change this value when the checkbox is pressed. (For example, if I have a checkbox with isChecked value of "false", when I want to press

How can I change the checked state to uncheck this Checkbox case?

Oscar Rojas Murillo Please help me here...I have a list of checkboxes with "isChecked" value in DB, but I don't know how to change this value when the checkbox is pressed. (For example, if I have a checkbox with isChecked value of "false", when I want to press

How can I change the checked state to uncheck this Checkbox case?

Oscar Rojas Murillo Please help me here...I have a list of checkboxes with "isChecked" value in DB, but I don't know how to change this value when the checkbox is pressed. (For example, if I have a checkbox with isChecked value of "false", when I want to press

How can i change the class on :checked div containing checkbox

Casimir I want to disable the :hovereffect on the div that includes my checkbox :checked. I tried: input[type=checkbox]:checked ~ #mydiv:hover {my:css} It only works on div/class that doesn't contain my checkbox. How can I do this? Here is my code: http://code

How can I change the checked state to uncheck this Checkbox case?

Oscar Rojas Murillo Please help me here...I have a list of checkboxes with "isChecked" value in DB, but I don't know how to change this value when the checkbox is pressed. (For example, if I have a checkbox with isChecked value of "false", when I want to press

How can I change the checked state to uncheck this Checkbox case?

Oscar Rojas Murillo Please help me here...I have a list of checkboxes with "isChecked" value in DB, but I don't know how to change this value when the checkbox is pressed. (For example, if I have a checkbox with isChecked value of "false", when I want to press