AngularJS ng-Submit Directive

AngularJS ng-Submit Directive: The ng-submit directive is used to binds the angular JS expressions to submit events. It just prevents the default actions only if the form does not contain action,data-action,x-action attributes. The ng-submit directive executes at a priority level 0.



AngularJS ng-Submit Directive Syntax

<form
ng-submit="expression">
...
</form>

ng-submit Directive Arguments 

Param type Details
ngSubmit expression Expression to eval. (Event object is available as $event)

AngularJS ng-submit Directive Example

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example - example-ng-submit-production</title>
<script src="//code.angularjs.org/snapshot/angular.min.js"></script>
</head>
<body ng-app="submitExample">
<script>
angular.module('submitExample', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.list = [];
$scope.text = 'hello';
$scope.submit = function() {
if ($scope.text) {
$scope.list.push(this.text);
$scope.text = '';
}
};
}]);
</script>
<form ng-submit="submit()" ng-controller="ExampleController">
Enter text and hit enter:
<input type="text" ng-model="text" name="text" />
<input type="submit" id="submit" value="Submit" />
<pre>list={{list}}</pre>
</form>
</body>
</html>

AngularJS ng-submit Example OutputAngular JS ng-submit Example Output