Ng-Submit-4

 

Ng-Submit-4

 
 
 
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Welcome to LearnKode - A code learning platform</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"></script> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> </head> <body ng-app="app"> <div ng-controller="ExampleController"> <div class="container"> <h3>Registration form.</h3> <form name="editForm" ng-submit="save(this)" novalidate> <div class="form-group"> <label for="name">Your Email </label> <input type="email" name="email" data-ng-model="email" class="form-control" required /> <span>{{errorMsg}}</span> </div> <input type="submit" class="btn btn-default" value="Submit"> </form> </div> </div> <script> var app = angular.module("app", []); app.controller('ExampleController', ['$scope', function ($scope) { $scope.save = function ($this) { if ($this.editForm.email.$error.required) { $scope.errorMsg = "This field is required"; } else if ($this.editForm.$invalid) { $scope.errorMsg = "Email is not valid"; } else { $scope.errorMsg = ""; alert("Form is valid."); } } }]); </script> </body> </html>
Output