Create a form with validation using AngularJS built-in directives.

<form name="myForm" ng-app="" ng-controller="FormController" novalidate>
    <label for="username">Username:</label>
    <input type="text" id="username" name="username" ng-model="user.username" required>
    <span ng-show="myForm.username.$error.required">Username is required.</span>

    <label for="email">Email:</label>
    <input type="email" id="email" name="email" ng-model="user.email" required>
    <span ng-show="myForm.email.$error.required">Email is required.</span>
    <span ng-show="myForm.email.$error.email">Invalid email address.</span>

    <input type="submit" value="Submit" ng-disabled="myForm.$invalid">
</form>

<script>
    function FormController($scope) {
        $scope.user = {};
    }
</script>

 

Post your Answer