angularjs - why checkbox is showing always false value -
i have html structure this
<div ng-controller="parentctrl"> <div ng-controller="childctrl"> <input ng-model="selectall" id="selectall" type="checkbox" ng-click="selectallchange()"></div> </div> </div> here js code
function parentctrl($scope) { $scope.selectall = false; $scope.selectallchange = function() { if($scope.selectall){ console.log('ttt'); } else console.log('fff'); } } on click of checkbox whether checked or not, in console getting fff how know checkbox checked or not in situation?
in code, ng-model binds childctrl's scope, code inside parentctrl accessing scope created parentctrl.
you try this instead of $scope scope triggering function:
if(this.selectall){ and use ng-change instead.
ng-change="selectallchange()" click , change events mean different things: click means mouse down , mouse on same element, change means value has changed. when use ng-click, ng-model does not update underlying value yet.
Comments
Post a Comment