1

I have a series of checkboxes in my ng-repeat as such:

<tr data-ng-repeat="item in blogCategory.items track by $index">
     ....
   <td>
      <label class="toggle">
      <input type="checkbox" name="checkbox-toggle" checked="checked"
         ng-model="blogCategory.items[$index].publish" ng-true-value="'YES'" ng-false-value="'NO'">
         <i data-swchon-text="YES" data-swchoff-text="NO"></i></label>
  </td>
</tr>

I have 2 category items in my sample, the first one is a false for publish, the second is a true. They are both returning as (false)/NO on the checkbox element.

The $scope vm is BlogCategory, the property/field is publish.

How do I correctly bind the input element above?

Thanks

2
  • can u make a fiddle? Commented Jan 25, 2015 at 12:05
  • What does your data-schwon-text directive do? Commented Jan 25, 2015 at 16:16

2 Answers 2

1

It looks like angular has changed parameter types for ngTrueValue and ngFalseValue from a string in 1.2.x to an expression in 1.3.x.

Try removing the single quotes around the values to make it look like

ng-true-value="YES" ng-false-value="NO"

You were probably looking at the documentation on latest as that's where it defaults to but your version may be 1.2.

https://code.angularjs.org/1.2.27/docs/api/ng/input/input%5Bcheckbox%5D

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

Comments

0

Here you go: http://jsfiddle.net/nx22cwwg/1/

So your problem is at the ng-model. You want item.publish there. So in my code ( which is almost the same as yours, I didn't look at exact property names and stuff ) I have:

<ul>
    <li data-ng-repeat="item in items">
      <input type="checkbox" name="checkbox-toggle" checked="checked"
       ng-model="item.isPublished" ng-true-value="YES" ng-false-value="NO" />
        {{ item.name}}
       </li>
</ul>

2 Comments

I don't think that is the issue, items[$index].isPublished works as well.
Good point - although it is devious in my opinion. But you are right indeed. Then I'd check the parentheses in the ng-true-value - or check any other differences with my jsfiddle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.