5

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.

1 Answer 1

6

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.)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.