AngularJS ng-submit Directive Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The ng-submit Directive in AngularJS is used to specify the functions to be run on submit events. It can be used to prevent the form from submission if it does not contain an action. It is supported by <form> element. Syntax: <form ng-submit="expression"> Content ... </form>Parameter: expression: When submitting the form, then the function will be invoked to evaluate an expression that will return the function call.Example 1: This example describes the basic use of the ng-submit Directive in AngularJS. HTML <!DOCTYPE html> <html> <head> <title>ng-submit Directive</title> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"> </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> Output: Example 2: This example describes the ng-submit Directive in AngularJS, where the greeting message will be displayed once the user is logged in. HTML <!DOCTYPE html> <html> <head> <title>ng-submit Directive</title> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.2/angular.min.js"> </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="form" ng-submit="login()" ng-hide="isShow"> User Name: <input type="text" ng-model="users.user" required /> <br /><br /> <button ng-disabled="form.$invalid"> Click to Login </button> </form> <br> <pre ng-show="isShow">Welcome <b>{{name}}</b> You are successfully login </pre> <input ng-show="isShow" type="button" value="Logout" ng-click="isShow=false" /> </div> <script> var app = angular.module("app", []); app.controller('geek', ['$scope', function ($scope) { $scope.users = { user: "" }; $scope.login = function () { $scope.isShow = true; $scope.name = $scope.users.user; $scope.users = { user: "" } }; }]); </script> </body> </html> Output: Comment More infoAdvertise with us Next Article AngularJS ng-required Directive V Vishal Chaudhary 2 Follow Improve Article Tags : Web Technologies AngularJS AngularJS-Directives Similar Reads AngularJS ng-paste Directive The ng-paste Directive in AngularJS is used to specify custom behavior functions when the text in input fields is pasted into an HTML element. It can be used to call a function that will be triggered when the text is pasted into the input field. It is supported by <input>, <select> and 2 min read AngularJS input Directive In this article, we will see how the input Directive in AngularJS can be utilized to change the default behavior of <input> elements. This can be done with the help of the ng-model attribute present inside the <input> element. <input> is an HTML tag that is used to get user data us 2 min read AngularJS ng-value Directive The ng-value Directive in AngularJS is used to specify the value of an input element. This directive can be used to achieve the one-way binding for the given expression to an input element, especially when the ng-model directive is not used for that specific element. It is supported by <input> 2 min read AngularJS ng-required Directive The ng-required Directive in AngularJS is used to specify the required attribute of an HTML element. The input field in the form is required only if the expression inside the ng-required directive returns true. It is supported by <input>, <select> and <textarea> tags. Syntax: <e 2 min read AngularJS | ng-selected Directive The ng-selected Directive in AngularJS is used to specify the selected attribute of an HTML element. It can be used to select the default value specified on an HTML element. If the expression inside the ng-selected directive returns true then the selected option value will be displayed otherwise not 1 min read AngularJS Directives Directives are markers in the Document Object Model(DOM). Directives can be used with any controller or HTML tag which will tell the compiler what exact operation or behavior is expected. There are some directives present that are predefined but if a developer wants he can create new directives (cus 9 min read Like