user3299182
user3299182

Reputation: 611

angular change ng-model dynamically

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

Upvotes: 1

Views: 147

Answers (1)

jvrdelafuente
jvrdelafuente

Reputation: 2002

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;

Upvotes: 1

Related Questions