I've been diving into the world of AngularJs and recently created a simple Angular application. In one section of this app, I utilized ngClass within a div element like below:
<div ng-class='{"some class": aFuncTruthyOrFalsy()}'>
<!-- The aFuncTruthyOrFalsy() function is implemented in the controller specific to this view-->
Interestingly, there's an unrelated input field in the same view that has no association with the aforementioned div or the values checked within the function.
I observed that every time I type something in the input field (be it a change event or keypress event), it triggers a reevaluation of the ngClass. (I confirmed this by adding a console log inside the aFuncTruthyOrFalsy function). I'm puzzled as to which events are actually causing this frequent reevaluation.
It appears that ngClass undergoes reevaluation upon each and every event occurrence on the page.
Could someone shed some light on this behavior?
Is there a way to cache the evaluated class during the initial loading of the view?
Moreover, imagine if multiple ngClass directives are used within the same view, and each expression evaluation is handed over to functions that perform complex operations to arrive at the final evaluated expression? How would that impact performance and behavior?