mardi 24 octobre 2017

Angularjs init checked status and ngModel value

I'm using angularjs 1.6.1

This is my HTML:

<label ng-if="parents.children" ng-repeat="child in parents.children" class="checkbox" >
    <input type="checkbox"
            ng-model="selected.category[parents.cat_ID][child.cat_ID]"
            id=""
            name=""
    >
    <i class="icon fa fa-circle-o"></i>
    <span class="name">  </span>
</label>

I need to do 2 things:

1) to show the checkboxes checked IF is true.

2) AND also to init the values found inside $scope.selected = {} (the ngModels)

My issue is that if I add to input:

ng-checked="child.found"

Then the checkboxes will be checked alright, but the $scope.selected will be completely empty. If I use instead:

ng-init="selected.category[parents.cat_ID][child.cat_ID] = child.found"

Then it will fill $scope.selected with the correct values, but shows the checkboxes checked status completely wrong checkbox status wrong

I have even tried

ng-false-value="false"
ng-true-value="true"

But nothing changed...

Appreciate any help! Thanks!




Aucun commentaire:

Enregistrer un commentaire