0

Why here i toggled the checkbox, it will be checked?

Why it is not controlled by the variable myVar1, i didn't set myVar1 to true on purpose to test.

I think it will always be unchecked, because i didn't set the myVar1 to true.

https://stackblitz.com/edit/angular-v4lsc6?file=src%2Fapp%2Fapp.component.html

component:

myVar1 = false;

template:

<input type="checkbox" [checked]="myVar1"/> myVar1 {{myVar1}}
5
  • 1
    It works for me. After setting myVar1 to true, the checkbox is checked. Commented Oct 1, 2021 at 14:05
  • @Tvde1 I want it always unchecked, if keep myVar1 always to false, i think the checkbox should be always unchecked Commented Oct 1, 2021 at 14:10
  • Set click to return a false: stackoverflow.com/questions/36017793/… Commented Oct 1, 2021 at 14:16
  • You want the checkbox to be readonly/disabled? Commented Oct 1, 2021 at 14:21
  • I want to the checkbox checked is only controlled by value of myVar1, no matter how user toggle the checkbox, if myVar1 is false, then it will not be checked, hope it's clear Commented Oct 1, 2021 at 14:25

0

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.