Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why do I see the method executed many times?
Message
From
29/05/2015 10:42:23
 
General information
Forum:
Javascript
Category:
Other
Miscellaneous
Thread ID:
01620290
Message ID:
01620331
Views:
34
>>>I put the breakpoint in the getFilteredTotal method and I can see it executed several times (when I got tired I removed the breakpoint). I think I've seen similar issues before.
>>>
>>>Why would angularJs JavaScript execute this code multiple times when it's in a table? It is not in the ng-repeat directive, right? As the tr tag is closed already.
>>
>>Same problem as in my last reply: It's probably being evaluated on every $digest cycle. Solution is the same.
>
>I am going to try to re-design it but if you can elaborate with a sample, it will be great.
>
>Thanks again.

There's an example in the documentation: https://docs.angularjs.org/guide/filter under 'Using filters in controllers,services and directives'

Snip from the docs :
" However, using a filter in a view template will reevaluate the filter on every digest, which can be costly if the array is big.

The example below therefore calls the filter directly in the controller. By this, the controller is able to call the filter only when needed (e.g. when the data is loaded from the backend or the filter expression is changed)."
Previous
Reply
Map
View

Click here to load this message in the networking platform