Tutorials References Exercises Bootcamps Videos Menu
Sign Up Create Website Get Certified Upgrade

AngularJS ng-submit Directive


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">


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!";
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.


<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.