最新的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.