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.

demo


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -