<!DOCTYPE html>
<
html
>
<
head
>
<
title
>ng-submit Directive</
title
>
<
script
src
=
</
script
>
</
head
>
<
body
ng-app
=
"app"
style
=
"text-align:center"
>
<
h1
style
=
"color:green"
>GeeksforGeeks</
h1
>
<
h2
>ng-submit Directive</
h2
>
<
div
ng-controller
=
"geek"
>
<
form
name
=
"form1"
ng-submit
=
"save(this)"
novalidate>
<
label
for
=
"name"
>Enter Email: </
label
>
<
input
type
=
"email"
name
=
"email"
data-ng-model
=
"email"
required />
<
br
>
<
span
>{{errorMsg}}</
span
>
<
br
>
<
input
type
=
"submit"
value
=
"Click it!"
>
</
form
>
</
div
>
<
script
>
var app = angular.module("app", []);
app.controller('geek', ['$scope', function ($scope) {
$scope.save = function ($this) {
if ($this.form1.email.$error.required) {
$scope.errorMsg = "This field is required";
}
else if ($this.form1.$invalid) {
$scope.errorMsg = "Email is not valid";
}
else {
$scope.errorMsg = "";
alert("The given Email is accepted.");
}
}
}]);
</
script
>
</
body
>
</
html
>