在文本字段中键入时,angularjs验证不会隐藏

时间:2015-11-23 01:18:34

标签: angularjs validation angularjs-ng-click

通过扩展答案in this question,我自己试图在输入文本字段时隐藏验证消息,

 $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中给出。为什么在满足条件的情况下验证不会隐藏?

1 个答案:

答案 0 :(得分:2)

您应该使用ngChnage代替ngClick http://jsfiddle.net/8z1uc011/1/