Is it a bad practice to use the return value of a function call inside ng-if. Will it affect the digest cycle/performance?
As any expression used in the view, it will be reevaluated at each digest cycle to see if its value has changed or not, and thus if the element must be removed or added to the DOM.
If the function is simple enough, no problem. If it tries to compute the 10000th decimal of pi, you'll have performance problems. What matters is to understand what you're doing, and how it works.
So if you feel using a function makes your code simpler, go for it, and start optimizing if you really need to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With