How can I force an angular validation directive to run?

前端 未结 2 796
借酒劲吻你
借酒劲吻你 2021-01-06 01:15

I\'ve created a validation directive for my form. It basically validates a fields value based on data from another field.

It works perfect :-)

My problem is

2条回答
  •  旧巷少年郎
    2021-01-06 01:24

    Maybe a simpler solution would be with a watcher or even an expression inside the ng-show direcive of your error span.

    Using an expression inside the ng-show directive would be like this:

       
    

    Otherwise you could watch for changes in the models int1 and int2 and compare their values:

    $scope.$watch('int1+int2', function () {
        if($scope.int1 > $scope.int2) {
            $scope.error = true;    
        }else {
            $scope.error = false;
        }
    }) 
    
     
    

    Here is a fiddle

提交回复
热议问题