最新的Web开发教程
 

AngularJS NG-提交指令


运行一个函数的形式提交时:

<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 yet clicked submit";
    $scope.myFunc = function () {
        $scope.myTxt = "You clicked submit!";
    }
});
</script>
</body>
试一试»

定义和用法

ng-submit指令指定提交表单时运行的功能。

如果表格没有一个action ng-submit将防止从形式提交。


句法

<form ng-submit=" expression "></form>

由<form>元素的支持。


参数值

Value Description
expression A function to be called when the form is being submitted, or an expression to be evaluated, which should return a function call.