Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular how to disable validation on condition ng-required

I have a variable on the scope which I use to check for condition

$scope.data = $resource().query(); //returns array always

So i have a regular validation with a ng-required directive

<input ng-required="{{data.length}}"/>

now when the data is initially loaded into a 2 length array the ng-required validates the field and everything works, but if I were to set ng-required to [], ng-required will still validate as a regular required,

$scope.$apply(function(){
    $scope.data = []
});

how do I disable validation on ng-validation = "false" again.

like image 417
user2167582 Avatar asked Sep 12 '13 17:09

user2167582


1 Answers

ng-required accepts an expression, no need to wrap in {{ }}

<input ng-required="data.length"/>

Basic Example: http://jsfiddle.net/TheSharpieOne/Uxe5Q/ (inspect to see the validation being added and removed.)

like image 107
TheSharpieOne Avatar answered Sep 27 '22 20:09

TheSharpieOne