Monday, 15 September 2014

angularjs - angular checkbox update is not updating the model -



angularjs - angular checkbox update is not updating the model -

i'm trying alter checkbox value based on checkbox value, alter doesn't seem have effect in model.

here code illustration of issue:

http://plnkr.co/edit/efon3cejwku01lkknc1s?p=preview

html file

<!doctype html> <html> <head> <script data-require="angular.js@*" data-semver="1.2.0-rc3-nonmin" src="http://code.angularjs.org/1.2.0-rc.3/angular.js"></script> <link data-require="bootstrap-css@*" data-semver="3.0.0" rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" /> <link rel="stylesheet" href="style.css" /> <script src="script.js"></script> </head> <body ng-app="main" ng-controller="democtrl"> <pre> value: {{a}} b value: {{b}} </pre> <input type="checkbox" ng-model="a" /> b <input type="checkbox" ng-model="b" ng-disabled="a" ng-checked="!a && b" /> </body> </html>

and empty controller:

var app = angular.module('main', []) .controller('democtrl', function($scope) { });

as far i've read, dom alter doesn't alter model, , when seek phone call $apply, digest running, i'm bit lost.

i don't want set $watch on first checkbox because illustration quite complex.

is there alternative solution not involve writing js code in controller problem?

please see http://plnkr.co/edit/lbowo4olbtghactuettd?p=preview

you missed reference script

<script src="//cdn.jsdelivr.net/angular.ngtable/0.3.3/ng-table.js"></script>

angularjs data-binding checkbox

No comments:

Post a Comment