forked from angular/code.angularjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular.directive.ng:eval.html
49 lines (48 loc) · 1.76 KB
/
angular.directive.ng: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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<h1>angular.directive.ng: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>The <code>ng:eval</code> allows you to execute a binding which has side effects
without displaying the result to the user.</p>
<h2>Usage</h2>
<h3>In HTML Template Binding</h3>
<tt>
<pre>
<ANY ng:eval="expression">
...
</ANY>
</pre>
</tt>
<h3>Parameters</h3>
<ul>
<li><tt>expression</tt> –
<tt>{expression}</tt>
<tt></tt>
– to eval.</li>
</ul>
<h2>Example</h2>
<p>Notice that <code>{{</code> <code>obj.multiplied = obj.a * obj.b</code> <code>}}</code> has a side effect of assigning
a value to <code>obj.multiplied</code> 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 <code>ng:eval</code> allows you to execute code without updating
the display.</p>
<doc:example>
<doc:source>
<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>
</doc:source>
<doc:scenario> 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');
});</doc:scenario>
</doc:example>