1

I'm trying to assign a value to a checkbox when checked and nothing (or false) when unchecked:

<input type="checkbox" [value]="key" [formControlName]="variable"/>

This doesn't work and the values are either true or false. Is it possible to assign a variable?

1 Answer 1

4

You could try this:

<input type="checkbox" (change)="$event.target.checked ? formGroupName.controls['variable'].setValue(key) : formGroupName.controls['variable'].setValue()" [formControlName]="variable"/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.