0

https://jsfiddle.net/bngk/7urrobaa/

 <div ng-repeat="item in items" ng-init="item.showCb = item.value == 'true' || item.value == 'false'">

<input type="checkbox" ng-if="item.showCb" ng-true-value="true" ng-false-value="false" ng-model="item.value" ng-checked="item.value == 'true'">{{items[$index].value}}</input>
    <input type="text" ng-if="!item.showCb"  ng-model="item.value"/>
  </div>

I have problem in binding the checkboxes in ng-repeat if I have few checked values by default where the values are not properly updated in the model and if all are non-checked by default, it works but the value is updated in the model, it holds boolean value though i mentioned ng-true-value="true" and ng-false-value="false" as string. I want the string value to be present in the model. Please check in my fiddle. Thanks for your support.

2
  • 1
    You have a lot of errors in your code... <input> is a self closing tag, ngModel and ngChecked shouldn't be used together. ngInit isn't for this purpose.. Commented Jul 28, 2016 at 12:18
  • Self closing tag and ng-init is fine. But without ng-checked, I am not able to set the values by default and without ng-model I am not able to bind the values. Please let me know how to use ng-model & ng-checked in this case...Thanks in advance... Commented Aug 2, 2016 at 11:26

1 Answer 1

2

If you have a look at the documentation: https://docs.angularjs.org/api/ng/input/input%5Bcheckbox%5D, you can see ng-*-value accepts an expression. So if you simply put ng-true-value="true", it sees that true as an expression.

If you put ng-true-value=" 'true' ", then it knows it is a string.

But as mentioned above, there are a couple of other mistakes in your code.

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.