AngularJS ng-submit Directive
Definition and Usage
ng-submit
The directive specifies the function to be run when submitting the form.
If the form does not have an action, ng-submit will prevent the form from being submitted.
Example
Run the function when submitting the form:
<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 clicked submit"; $scope.myFunc = function () { $scope.myTxt = "You clicked submit!"; } }); </script> </body>
Syntax
<form ng-submit="expression</form>
Affected <form>
Element Support.
Parameters
Parameters | Description |
---|---|
expression | The function to be called when submitting a form, or the expression to be calculated, should return the function call. |