$rootScope.Scope.$eval()

$eval([expression], [locals]);

Executes the expression on the current scope and returns the result. Any exceptions in the expression are propagated (uncaught). This is useful when evaluating Angular expressions.

var scope = ng.$rootScope.Scope();
scope.a = 1;
scope.b = 2;

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

Parameters

Param Type Details
expression
(optional)
stringfunction()

An angular expression to be executed.

  • string: execute using the rules as defined in expression.
  • function(scope): execute the function with the current scope parameter.
locals
(optional)
object

Local variables object, useful for overriding values in scope.

Returns

*

The result of evaluating the expression.

doc_AngularJS
2016-03-29 16:10:39
Comments
Leave a Comment

Please login to continue.