angular.directive.ng:eval

Work in Progress This page is currently being revised. It might be incomplete or contain inaccuracies.

Description

The ng:eval allows you to execute a binding which has side effects without displaying the result to the user.

Usage

<ANY ng:eval="expression">
   ...
</ANY>

Parameters

Example

Notice that {{ obj.multiplied = obj.a * obj.b }} has a side effect of assigning a value to obj.multiplied and displaying the result to the user. Sometimes, however, it is desirable to execute a side effect without showing the value to the user. In such a case ng:eval allows you to execute code without updating the display.

       <input name="obj.a" value="6" >
<input name="obj.b" value="2">
         = {{obj.multiplied = obj.a * obj.b}} <br>
       <span ng:eval="obj.divide = obj.a / obj.b"></span>
       <span ng:eval="obj.updateCount = 1 + (obj.updateCount||0)"></span>
       <tt>obj.divide = {{obj.divide}}</tt><br/>
       <tt>obj.updateCount = {{obj.updateCount}}</tt>
     
       it('should check eval', function(){
         expect(binding('obj.divide')).toBe('3');
         expect(binding('obj.updateCount')).toBe('2');
         input('obj.a').enter('12');
         expect(binding('obj.divide')).toBe('6');
         expect(binding('obj.updateCount')).toBe('3');
       });