vendredi 9 octobre 2015

Checkbox return false instead true in ng-click

In below code $scope.checkboxModel set to false. When I click on checkbox and debug code on first click, it return false instead of true when checkbox is checked.

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
  $scope.showPassword = '';
  $scope.password = '';
  $scope.checkboxModel = false;
  $scope.showHidePassword = function(checkboxModel) {
    $scope.showPassword = checkboxModel ? '' : $scope.password;
  }
});
<script src="http://ift.tt/1mQ03rn"></script>
<div ng-app="myApp" ng-controller="myCtrl">
  <div class="input-group bmargindiv1 col-md-12">
    <span class="input-group-addon ndrftextwidth text-right" style="width:180px">Password :</span>
    <input type="password" name="itemname" id="contactno" class="form-control" placeholder="password" ng-model="password">
  </div>
  <div class="input-group bmargindiv1 col-md-12">
    <span class="input-group-addon ndrftextwidth text-right" style="width:180px">Show me Password <input type="checkbox" ng-model="checkboxModel" ng-click="showHidePassword(checkboxModel)" /></span>
    <input type="text" name="itemname" id="contactno" class="form-control" placeholder="password" ng-model="showPassword" readonly="readonly">
  </div>
</div>

Why it is not returning true for first time when checkbox is checked?




Aucun commentaire:

Enregistrer un commentaire