ng-submit

Description

ng-submit binds an expression to an onsubmit event.

This directive prevents the default action, but only if the form does not contain an action attribute.

Example

The following code shows how to ng-submit.


<!doctype html>
<!--<!--  w  ww.  jav a  2  s  . c  o  m-->
Created using JS Bin
http://jsbin.com

Copyright (c) 2014 by auser (http://jsbin.com/ONIcAC/1/edit)

Released under the MIT license: http://jsbin.mit-license.org
-->
<html ng-app="myApp">
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.js"></script>
</head>
<body>
  
<form ng-submit="submit()" ng-controller="FormController">
  Enter text and hit enter:
  <input type="text" ng-model="person.name" name="person.name" />
  <input type="submit" name="person.name" value="Submit" />
  <ul ng-repeat="(index, object) in people">
    <li>{{ object.name }}</li>
  </ul>
</form>
  
<script id="jsbin-javascript">
angular.module('myApp', [])
.controller('FormController', function($scope) {

  $scope.person = {
    name: null
  };

  $scope.people = [];

  $scope.submit = function() {
    if ($scope.person.name) {
      $scope.people.push({name: $scope.person.name});
      $scope.person.name = '';
    }
  };
});
</script>
</body>
</html>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Tutorial »




Introduction
Buildin Filters
Buildin Directives