Somehow, through the magic of Angular, if you use ng-model
and provide it a boolean, your checkbox will be checked if said boolean is true, and unchecked if false.
<input type="checkbox" ng-model="video.hidden">
While this alone is fairly baffling, I'm actually trying to reverse the checked state, because unlike the todo example where todo.done
means the box gets checked, my model is more like todo.incomplete
.
Unfortunately my first guess didn't work:
<input type="checkbox" ng-model="!video.hidden">
I'm in a position where the model has been dictated to me, so I can't change it and don't want to have to massage it on the client (because I'm sending client objects back to the server, since it's running in a trusted environment).
Update
This works in 1.3 and doesn't give you strings (1.2.xxx gave you strings instead of booleans):
<input type="checkbox" ng-model="video.hidden" ng-true-value="false" ng-false-value="true">
You can make that now without a need of custom directive, angular support ng-true-value
and ng-false-value
https://docs.angularjs.org/api/ng/input/input[checkbox]
your example should work now <input type="checkbox" ng-model="video.hidden" ng-true-value="false" ng-false-value="true">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With