jay
jay

Reputation: 1471

Angular ng-disabled with function

I want to use disabled-ng with dynamic value returned from a function.

I have tried several ways but it is not working.

<textarea id="{{exercise.type}}" ng-disabled={{prova}}></textarea>
......
<textarea id="{{exercise.type}}" ng-disabled=prova></textarea>
......
<textarea id="{{exercise.type}}" ng-disabled=prova()></textarea>

with this javascript function

$scope.prova=function(e){               
               return true;
       };

Upvotes: 13

Views: 58908

Answers (2)

Mike Mason
Mike Mason

Reputation: 3

Digest loops happen when the function, changes view model data. If your function does not change the view model, it shouldn't cause a digest loop.

ng-if is a good example of something that will cause a digest loop.

This is in response to 'what to do when you have a digest loop.'

Answer:

Don't use function in things that trigger the view model.

Upvotes: 0

Ivan Chernykh
Ivan Chernykh

Reputation: 42166

Try this syntax:

ng-disabled="prova()"

Example: http://jsfiddle.net/3eqz2/2/

Upvotes: 31

Related Questions