AngularJS Tutorial - ng-submit calls custom function








The following code shows how to use ng-submit to call custom function.

Example


<!--from  ww  w  .  j ava  2s.c om-->
<!doctype html>
<html ng-app="myApp" >
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js"></script>
  <script>
var app = angular.module('myApp', []);

app.controller('MainCtrl', function($scope) {
  $scope.showAlert = function(q) {
    console.log(q);
  }; 
});
  
  </script>
</head>
<body ng-controller="MainCtrl">
  <form ng-submit="showAlert(q)">
    <input ng-model="q">Press enter to submit
  </form>
</body>
</html>

The code above is rendered as follows: