angular.scope.$eval

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

Description

Without the exp parameter triggers an eval cycle, for this scope and it's child scopes.

With the exp parameter, compiles the expression to a function and calls it with this set to the current scope and returns the result.

Example

         var scope = angular.scope();
         scope.a = 1;
         scope.b = 2;

         expect(scope.$eval('a+b')).toEqual(3);
         expect(scope.$eval(function(){ return this.a + this.b; })).toEqual(3);

         scope.$onEval('sum = a+b');
         expect(scope.sum).toEqual(undefined);
         scope.$eval();
         expect(scope.sum).toEqual(3);
       

Usage

angular.scope.$eval(exp);

Parameters

Returns

{*} The result of calling compiled exp with this set to the current scope.