介绍
http://docs.ngnice.com/api/ng/directive/ngSubmit
定义和用法
语法
<form ng-submit="expression"></form>
<form> 元素支持该属性。
参数值
expression 表单提交后函数将被调用,或者一个表达式将被执行,表达式返回函数调用。
例子
<!doctype html> <html lang="en"> <head> <Meta charset="UTF-8"> <title>Example - example-example32-production</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.17/angular.min.js"></script> </head> <body ng-app=""> <script> function Ctrl($scope) { $scope.list = []; $scope.text = 'hello'; $scope.submit = function() { if ($scope.text) { $scope.list.push(this.text); $scope.text = ''; } }; } </script> <form ng-submit="submit()" ng-controller="Ctrl"> Enter text and hit enter: <input type="text" ng-model="text"/> <input type="submit" /> <pre>list={{list}}</pre> </form> </body> </html>