ng-submitChỉ thị AngularJS


Thí dụ

Chạy một chức năng khi biểu mẫu được gửi:

<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>

Định nghĩa và Cách sử dụng

Lệnh ng-submitchỉ định một hàm để chạy khi biểu mẫu được gửi.

Nếu biểu mẫu không có dấu action ng-submitsẽ ngăn không thể gửi biểu mẫu.


Cú pháp

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

Được hỗ trợ bởi phần tử <form>.


Giá trị tham số

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.