1

So, this seems like it must be a newb question. Here is a plunkr http://plnkr.co/edit/r9xWht5DZtOTvbblXwYZ

<input id="reviews"  ng-model="reviews" type="checkbox" ng-checked="reviews == 1" />

Basically I have a boolean in the db that I set scope to, it is either 1 or 0 in db. If it is true then the checkbox is checked, if not then it isn't. The problem I am having is that if it is checked, the first time 1 uncheck the box, scope doesn't change. When I click it (check it again) the scope value turns into true, then it works as expected.

Again, I must be overlooking something trivial here. I was looking into $scope.$watch should I be using that?

Thanks!

2 Answers 2

1

Instead of ng-checked you can use ng-true-value and ng-false-value instead.

See plunker

<input id="reviews"  ng-model="reviews" type="checkbox" ng-true-value="1" ng-false-value="0" />
Sign up to request clarification or add additional context in comments.

1 Comment

I just came back to answer my question with this, that was fast!
1

Your problem is using ng-checked with ng-model. The documentation says:

Note that this directive should not be used together with ngModel, as this can lead to unexpected behavior.

Both try to set the value of the input field and this leads to the weird results you're having.

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.