I'm wondering if it's possible to have a ng-class with class one time binded and class which are evaluated each digest cycle.
<div ng-class="{'one_time_binded_class': isMonkey(), 'not_one_time_binded_class': isUnicorn()}"></div>
I know I can one time bind the complete ng-class with ng-class="::{...}"
but my need is to one time bind a particular expression
Of course, this thing doesn't work :
<div ng-class="{'my_static_class': ::isMonkey(), 'my_dynamic_class': isUnicorn()}"></div>
Is there a way to do it ?
One way I can think of doing this (if I followed what you were trying to say) is as follows...
JSFiddle
An important part of one time binding is that it not be bound until the 'expression' is not undefined. The best answer so far, by @ifadey, his Method 1 evaluates to an empty string when 'expression' is undefined, which get's bound. This is contrary to the expected feature behavior. Method 2 is equally unhelpful in this late binding scenario.
Do do this correctly, directly answering op's question:
or the more technically correct but ugly:
Method 1:
Method 2: