1

I have a checkbox (bound to a model), placed inside an ng-repeat tag which iterates over a list.

I want to send a value "YES" or "NO" depending on whether the box is checked or not to the controller using the ng-true-value and ng-false-value attributes.

But for some reason, the $scope.value2 is not getting updated in the controller.

Here is a jsFiddle with my problem:: http://jsfiddle.net/HmvgW/

Note: If I place the checkbox outside the ng-repeat tag, the YES/NO value is sent correctly to the controller.

How do I send a value to checkbox clicked value to the controller if I place it inside the ng-repeat tag?

Thanks!

1 Answer 1

5

It's a scope issue. ng-repeat creates a new child scope with each loop. If you want to access the parent scope from within the child, you can do so with $parent.value2.

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

2 Comments

Yes, I got it working by adding the $parent.value to the input tag. <input type="checkbox" ng-model="$parent.value2" ng-true-value="YES" ng-false-value="NO" ng-click="value2Clicked()"> Thanks!
@Wilson - thanks this really helped. What a strange bug.

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.