我需要驗證文本框。我正在使用ng-required =「true」,但它沒有顯示所需的消息。如果我點擊保存按鈕,它直接放置保存()功能。如何避免它。如何驗證AngularJS中的文本框
<div ng-app="LearnApp" ng-controller="csrControl">
<table>
<tr>
<td>
Name
</td>
<td>
:
</td>
<td>
<input id="txtName" type="text" ng-model="txtName" ng-required="true" placeholder="Name" />
</td>
</tr>
<tr>
<td>
Address
</td>
<td>
:
</td>
<td>
<input id="txtAddress" type="text" ng-model="txtAddress" ng-required="true" placeholder="Address" />
</td>
</tr>
<tr>
<td colspan="3" align="right">
<input id="btnSave" type="button" value="Save" class="button" ng-click="save()" />
<input id="btnCancel" type="button" value="Cancel" class="button" />
</td>
</tr>
</table>
</div>
<script type="text/javascript">
var app = angular.module("LearnApp", []);
app.controller("csrControl", function ($scope, $http) {
$scope.save = function() {
};
});
</script>
與嘗試,它只是「必要」,不NG-所需=「真」 – rrd
請檢查angularjs –
哪條消息,你希望看到的表單驗證?我沒有看到任何包含(錯誤)消息的html。或者你只是想觸發html5驗證? – devqon