Tuesday, 2 September 2014

AngularJS Required Field Validation for textbox

<!doctype html>
<html>

<head>
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.0/angular.min.js"></script>
</head>

<body ng-app="myApp">
  <script>
    angular.module('myApp', [])
      .controller('myCtrl', ['$scope',
        function($scope) {
          $scope.text = '';
        }
      ]);
  </script>
  <style>.error{color:red}</style>

  <form name="myForm" ng-controller="myCtrl">
    Enter Your Name :
    <input type="text" name="input" ng-model="text" required>
    <span class="error" ng-show="myForm.input.$error.required">
      Required!</span>
      <br/>
    <br/>My Name is {{text}}
  </form>
</body>

</html>

________________________________________________________________________________

ng-show : show / hide html contain base on expression 

required : bind with input text type control to validate required field for form
________________________________________________________________________________
output





1 comment: