I have a problem with binding Angular ng-check to ng-model, i.e. ng-model does not recognize the selected state of my flags.
Here is a description (its a much larger code base, but I'm considering minimizing the code).
When loading a page in JavaScript, I initialize my products and set default values:
$scope.products = {} $scope.SetProductsData = function() { var allProducts; allProducts = [ { id: 1, name: "Book", selected: true }, { id: 2, name: "Toy", selected: true }, { id: 3, name: "Phone", selected: true }]
I have a main control that displays a check box for each of the three products (book, toy and phone): they are checked by default
<div style="float:left" ng-init="allProducts.products = {}" > <div ng-repeat="p in Data.products"> <div style="font-size: smaller"> <label><input id="divPlatorm" ng-model="products[p.name]" ng-init="products[p.name] = true" type="checkbox"/> {{p.name}}</label> </div> </div> </div>
Then a table in which the same products are repeated in rows:
<div ng-repeat="line in lineProducts" ng-init="line.products = {}"> <div id="sc-p-enc" ng-repeat="p in Data.products"> <div id="sc-p-plat" style="font-size: smaller"> <label id="pl-label"><input ng-checked="products[p.name]" ng-model="line.products[p.name]" ng-init="line.products[p.name] = true" type="checkbox"/> {{p.name}}</label> </div> </div> </div>
When I check / uncheck the boxes for the master products, the corresponding flags change in the lines. So if I have 100 lines with (Book, Toy and Phone), an untested Toy, I can see where all the toys are not marked in the lines.
When I send data to the controller, I still see all the toys = true, even if they were not marked.
If I physically go to the line, then uncheck each toy and send the data to my controller Toys = False.
How can I change selected flags if they are controlled using the main flags?
I followed the post found here, but I don't think this applies to my scenario: AngularJS: ng model not bound to flags ng-check for flags