Chỉ thị ng-submit
của AngularJS
Ví 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>
Hãy tự mình thử »Định nghĩa và cách sử dụng
Lệnh ng-submit
chỉ định một hàm sẽ chạy khi biểu mẫu được gửi.
Nếu biểu mẫu không có action
ng-submit
sẽ ngăn việc 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. |