Tutorials References Exercises Videos Menu
Create Website Get Certified Upgrade

AngularJS ng-submit Directive


Example

Run a function when the form is submitted:

<body ng-app="myApp" ng-controller="myCtrl">

<form ng-submit="myFunc()">
    <input type="text">
    <input type="submit">
</form>

<p>{{myTxt}}</p>

<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
    $scope.myTxt = "You have not yet clicked submit";
    $scope.myFunc = function () {
        $scope.myTxt = "You clicked submit!";
    }
});
</script>
</body>
Try it Yourself »

Definition and Usage

The ng-submit directive specifies a function to run when the form is submitted.

If the form does not have an action ng-submit will prevent the form from being submitted.


Syntax

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

Supported by the <form> element.


Parameter Values

Value Description
expression A function to be called when the form is being submitted, or an expression to be evaluated, which should return a function call.