angularjs 在文本字段中输入时不会隐藏验证
angularjs validation is not hiding on typing in the text field
通过扩展答案 ,我自己试图隐藏在文本字段中键入时的验证消息,
$scope.click = function () {
showVal();
}
function showVal() {
$scope.count = 0;
for (var i = 0; i < $scope.myData.length; i++) {
if ($scope.myData[i].string === "") {
$scope.count++;
}
}
}
我的文本字段是,
<div ng-repeat="str in myData">
<input type="text" ng-model="str.string" ng-click="click()">
</div>
<br/> <span ng-if="count >= 1" style="color:red;">One or more string is empty</span>
如 this fiddle 中所示。为什么在满足条件的情况下验证没有隐藏?
您应该使用 ngChnage
而不是 ngClick
http://jsfiddle.net/8z1uc011/1/
通过扩展答案
$scope.click = function () {
showVal();
}
function showVal() {
$scope.count = 0;
for (var i = 0; i < $scope.myData.length; i++) {
if ($scope.myData[i].string === "") {
$scope.count++;
}
}
}
我的文本字段是,
<div ng-repeat="str in myData">
<input type="text" ng-model="str.string" ng-click="click()">
</div>
<br/> <span ng-if="count >= 1" style="color:red;">One or more string is empty</span>
如 this fiddle 中所示。为什么在满足条件的情况下验证没有隐藏?
您应该使用 ngChnage
而不是 ngClick
http://jsfiddle.net/8z1uc011/1/