13

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;
       };
0

2 Answers 2

31

Try this syntax:

ng-disabled="prova()"

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

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

3 Comments

using a function can cause a $digest iterator overload, when the element is bound to a model that is loaded dynamically
@GregJF I am having a problem with $digest iterator overload. How do you work around this?
function should be fast and simple, return value for example, calculate this value when something changes, for example use get/set function on your model properties to calculate valuefor ng-disabled function. Also angular often can use valueOf or toString, if you are return an object in prova() function
0

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.

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.