1

I have a checkbox and I'd like to change the value if the checkbox is checked or not.

For the moment, my checkbox model value is equal to 'true' if checked and 'false' if unchecked.

My checkbox

<input type="checkbox" ng-model="toStringObj" />

What I tried

<input type="checkbox" ng-true-value="anyModel" ng-false-value="''" ng-model="toStringObj" />

I works if I put a string in ng-true-value directive, but not with a model, I need to pass a model from my scope

1 Answer 1

1

Unfortunately ngTrueValue and ngFalseValue only accept constant expressions so it's not possible for them to be set dynamically from a value on your controllers scope.

Some attributes used in conjunction with ngModel (such as ngTrueValue or ngFalseValue) will only accept constant expressions.

https://docs.angularjs.org/error/ngModel/constexpr

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.