5

item.imposed is either 1, or 0.

In order for a checkbox to mark as checked, the value must be true or false.

<input type="checkbox" ng-model="item.imposed">

You cannot use a filter inside of ng-model, how can this be accomplished simply and correctly?

2 Answers 2

11

You can use ngChecked, but you won't get any binding back to your model:

http://jsfiddle.net/fMBQj/

Or you can use ngTrueValue and ngFalseValue, but you HAVE to use a string (not an int):

http://jsfiddle.net/fMBQj/1/

Or you can use a custom directive... it's pretty lame right now.

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

1 Comment

Langdon to the rescue! ngTrueValue works great, and it will work for many other value. Thanks tons
3

You can use ng-value-true to tell angular that your ng-model is a string.

I could only get ng-true-value working if I added the extra quotes like so (as shown in the official Angular docs - https://docs.angularjs.org/api/ng/input/input%5Bcheckbox%5D)

ng-true-value="'1'"

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.