forked from angular/code.angularjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular.scope.$eval.html
32 lines (28 loc) · 1.4 KB
/
angular.scope.$eval.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<h1>angular.scope.$eval</h1>
<fieldset class="workInProgress"><legend>Work in Progress</legend>
This page is currently being revised. It might be incomplete or contain inaccuracies.</fieldset>
<h2>Description</h2>
<p>Without the <code>exp</code> parameter triggers an eval cycle, for this scope and it's child scopes.</p>
<p>With the <code>exp</code> parameter, compiles the expression to a function and calls it with <code>this</code> set
to the current scope and returns the result.</p>
<h3>Example</h3><div ng:non-bindable><pre class="brush: js; html-script: true;">
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);
</pre></div><h2>Usage</h2>
<div ng:non-bindable=""><pre class="brush: js; html-script: true;">angular.scope.$eval(exp);</pre>
</div>
<h3>Parameters</h3>
<ul class="parameters"><li><code ng:non-bindable="">exp<i>(optional)</i> – {(string|function())} – </code>
An angular expression to be compiled to a function or a js
function.</li>
</ul>
<h3>Returns</h3>
<code ng:non-bindable="">*</code>
– The result of calling compiled <code>exp</code> with <code>this</code> set to the current scope.