1

I have this i a directive:

 if (scope.quesProp.required) {
            scope.required = '!someSelected(choices.selectedStuff)';
        } else {
            scope.required = false;
        }

and this in the template:

< some input val....
ng-required= 'required'
 ..>

I want it to change between false and !someSelected(choices.selectedStuff), it's not working if i do the above, and everything works great if in the template i change it back to this:

ng-required='!someSelected(choices.selectedStuff)'
1
  • 1
    Why not use a scope-function? e.g.: ng-required="isFieldRequired()"? And let that function return true/false. Commented Jul 31, 2014 at 11:51

1 Answer 1

1

You can do something like this:

< some input val....
ng-required= cond && !someSelected(choices.selectedStuff)
 ..>

If cond has the value false, the rest condition will be ignored, and if the cond is true, the next condition will be evaluated.

You can change the cond variable from your controller.

//var cond= true/false;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.