AngularJS Tutorial - Submit form with ng-click








The following code shows how to submit form with ng-click.

Example


<!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', []);
<!-- ww  w .j  a  v a 2s.  c o m-->
app.controller('MainCtrl', function($scope) {
  $scope.showAlert = function(q) {
    console.log(q);
  }; 
});
  
  </script>
</head>
<body ng-controller="MainCtrl">
  <form>
    <input ng-model="q">
    <button ng-click="showAlert(q)">Search</button>
  </form>
</body>
</html>

The code above is rendered as follows: