AngularJS Tutorial - Bind form error message








The following code shows how to Bind form error message.

Example


<!DOCTYPE html>
<html  ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
</head><!--from  w  w  w .java2s. c o  m-->
<body ng-app="myApp">
  <div ng-controller="MyCtrl">
    <form name="form">
        <input type="number" name="name" ng-model="id" required>
        <p>form.name.$error: {{form.name.$error}}</p>
    </form>
</div>
<script type='text/javascript'>

var myApp = angular.module('myApp',[]);

function MyCtrl($scope) {
    $scope.id = null;
}
</script>
</body>
</html>

The code above is rendered as follows: