javascript - Using ng-checked on checkbox in nested ng-repeat is always true -


i using nested ng-repeats display content on page. nested ng-repeat displays checkbox , checked status of checkbox should set boolean value of data in ng-repeat. using ng-checked , passing in truthy value, however, checkboxes checked regardless of value.

i have simplified code demo displays behaviour jsfiddle.

html

<div ng-app="myapp">     <div ng-controller="mycontroller">         <div ng-repeat="item in myarray">             <h3>{{ $index }}.&nbsp;{{ item.title }}</h3>             <div ng-repeat="child in item.subarray">                 <h4>({{ child.id }}). {{child.title}} </h4>                 <input type="checkbox" ng-checked="child.result" />                 <h6>answer is: {{ child.result }}</h6>             </div>         </div>     </div> </div> 

javascript

var myapp = angular.module('myapp', []);  function mycontroller($scope) {    $scope.myarray = [             { id: "1", title: "my array 1", subarray: [                 { id: "1", title: "my sub array 1", result: "false" },                 { id: "1", title: "my sub array 2", result: "true" },                 { id: "1", title: "my sub array 3", result: "false" },                 { id: "1", title: "my sub array 4", result: "true" },                 { id: "1", title: "my sub array 5", result: "false" }]             },             { id: "1", title: "my array 2", subarray: [                   { id: "1", title: "my sub array 1", result: "true" },                   { id: "1", title: "my sub array 2", result: "false" },                   { id: "1", title: "my sub array 3", result: "true" },                   { id: "1", title: "my sub array 4", result: "false" },                   { id: "1", title: "my sub array 5", result: "true" }]             },             {                 id: "1", title: "my array 3", subarray: [                     { id: "1", title: "my sub array 1", result: "false" },                     { id: "1", title: "my sub array 2", result: "false" },                     { id: "1", title: "my sub array 3", result: "true" },                     { id: "1", title: "my sub array 4", result: "false" },                     { id: "1", title: "my sub array 5", result: "false" }]             },             {                 id: "1", title: "my array 4", subarray: [                     { id: "1", title: "my sub array 1", result: "true" },                     { id: "1", title: "my sub array 2", result: "false" },                     { id: "1", title: "my sub array 3", result: "false" },                     { id: "1", title: "my sub array 4", result: "false" },                     { id: "1", title: "my sub array 5", result: "true" }]             },             {                 id: "1", title: "my array 5", subarray: [                     { id: "1", title: "my sub array 1", result: "true" },                     { id: "1", title: "my sub array 2", result: "true" },                     { id: "1", title: "my sub array 3", result: "false" },                     { id: "1", title: "my sub array 4", result: "true" },                     { id: "1", title: "my sub array 5", result: "true" }]             }         ]; } 

can explain why behaviour occurs , me understand how rectify it?

because child.result string , not boolean condition true.

use following:

ng-checked="child.result == 'true'" 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -