Saturday 17 January 2015

An example of show-password using ng-model in Angular JS


angularjs
It's sometime become so disgusting while typing password, dealing with all those **** or $$$$ or sometimes all blank. God save us.. but not all of them, some sites or apps provide an option like show password while typing, where you can see the password you type. I think it's more user interactive when it's become your choice to reveal your password on the screen while typing. 
   I found it so easy to do such thing in angularjs  all you need is ng-model directive and a little jquery coding and that will prepare your meal.
      The ng-model binds the data of HTML element (custom form control) like input, select, textarea etc.). It actually binds the control to a property on the scope using NgModelController, which is created and exposed by this directive.

Here is a small example how ng-model binds input control to a view.

<!DOCTYPE html>
<html ng-app>
  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js" data-semver="1.0.8"></script>
    <script>
    $(document).ready(function() {
    if($(this).prop("checked")==true)
      $("p").show();
    else
      $("p").hide();

      $("#chk").click(function() {
        if($(this).prop("checked")==true)
          $("p").show();
        else
          $("p").hide();
      });
});
    </script>
  </head>

  <body>
    <input type="password" id="pass" value="" ng-model="pass">
    <br>Show password : <input type="checkbox" id="chk" ><br>
    <p id="showPass">{{pass}}</p>
  </body>
</html>
AngularJS Plunker
Show password :
{{pass}}

No comments: