Simple Hide/Show Password Using AngularJS

In this tutorial, we will create a Simple Hide/Show Password Using AngularJS. AngualarJS is a structural framework for dynamic web application. It is a kind of template that extends HTML to a new level of coding techniques. It is mostly used by other well known site for creating a template. So let's get started. Creating A Mark Up To create a form, open any kind of text editor(notepad++, etc). Then copy/paste the code below, and save it 'index.html'
  1. <!DOCTYPE html>
  2. <html lang = "en">
  3.         <head>
  4.                 <link rel =  "stylesheet" type = "text/css" href = "css/bootstrap.css"/>
  5.                 <script src = "js/angular.js"></script>
  6.                 <script src = "js/script.js"></script>
  7.         </head>
  8. <body ng-app = "myModule">
  9.         <nav class = "navbar navbar-default">
  10.                 <div class = "container-fluid">
  11.                         <a class = "navbar-brand" href = "https://www.sourcecodester.com">Sourcecodester</a>
  12.                 </div>
  13.         </nav>
  14.         <div class = "row">
  15.                 <div class = "col-md-3"></div>
  16.                 <div class = "col-md-6 well" ng-controller = "myController">
  17.                 <h3 class = "text-primary">Simple Show/Hide Password Using Angular.js</h3>
  18.                 <hr style = "border-top:1px dotted #000;" />
  19.                 <div style = "width:20%;">
  20.                         <input type = "checkbox" ng-model = "hidePass" /><label>Show Password</label>
  21.                 </div>         
  22.                 <br /><br /><br />
  23.                 <table class = "table table-bordered alert-warning">
  24.                         <thead>
  25.                                 <tr>
  26.                                         <th>Name</th>
  27.                                         <th>Username</th>
  28.                                         <th ng-hide = "hidePass">Password</th>
  29.                                         <th ng-show = "hidePass">Password</th>
  30.                                 </tr>
  31.                         </thead>
  32.                         <tbody>
  33.                                 <tr ng-repeat = "member in members">
  34.                                         <td>{{member.name}}</td>
  35.                                         <td>{{member.username}}</td>
  36.                                         <td ng-hide = "hidePass">************</td>
  37.                                         <td ng-show = "hidePass">{{member.password}}</td>
  38.                                 </tr>
  39.                         </tbody>
  40.                 </table>
  41.                 </div>
  42.         </div>
  43. </body>
  44. </html>
The code above will display all the data from the angularjs script. The ng-show is an attribute that express in showing a targeted element. The ng-hide is an attribute that express in hiding a targeted element. Creating a script To make the function worked, we will try to create functional script. To do that copy/paste the code below, then name it "script.js"
  1. var myApp = angular.module("myModule", [])
  2.                                  .controller("myController", function($scope){
  3.                 var members = [
  4.                         {name: "Juan Dela Cruz", username: "handsome", password: "imagay"},
  5.                         {name: "San Pedro", username: "awesome", password: "tothemax"},
  6.                         {name: "Luis Buitton", username: "flying", password: "withoutwings"},
  7.                         {name: "San Carlos", username: "bridge", password: "birche"},
  8.                         {name: "Abra", username: "Kadabra", password: "alakazam"}
  9.                 ];
  10.                 $scope.members = members;
  11. });
The code above will now worked, when the user checked the show password the hidden password will show its meaning. There you have it, we created a simple hide/show password. I hope that this tutorial help you to your projects. For more updates and tutorials just kindly visit this site. Enjoy Coding!!
Tags

Add new comment