forked from angular/code.angularjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular.Array.count.html
51 lines (49 loc) · 2.39 KB
/
angular.Array.count.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
50
51
<h1>angular.Array.count</h1>
<div class="angular-array-count"><h2>Description</h2>
<div class="description"><p>Determines the number of elements in an array. Optionally it will count only those elements
for which the <code>condition</code> evaluates to <code>true</code>.</p>
<p>Note: this function is used to augment the <code>Array</code> type in angular expressions. See
<a href="#!angular.Array"><code>angular.Array</code></a> for more info.</p></div>
<h2>Usage</h2>
<div class="usage"><div ng:non-bindable=""><pre class="brush: js; html-script: true;">angular.Array.count(array[, condition]);</pre>
</div>
<h3>Parameters</h3>
<ul class="parameters"><li><code ng:non-bindable="">array – {Array} – </code>
<p>The array to count elements in.</p></li>
<li><code ng:non-bindable="">condition<i>(optional)</i> – {(function()|string)} – </code>
<p>A function to be evaluated or angular expression to be
compiled and evaluated. The element that is currently being iterated over, is exposed to
the <code>condition</code> as <code>this</code>.</p></li>
</ul>
<h3>Returns</h3>
<div class="returns"><code ng:non-bindable="">{number}</code>
– <p>Number of elements in the array (for which the condition evaluates to true).</p></div>
</div>
<h2>Example</h2>
<div class="example"><doc:example>
<pre class="doc-source">
<pre ng:init="items = [{name:'knife', points:1},
{name:'fork', points:3},
{name:'spoon', points:1}]"></pre>
<ul>
<li ng:repeat="item in items">
{{item.name}}: points=
<input type="text" name="item.points"/> <!-- id="item{{$index}} -->
</li>
</ul>
<p>Number of items which have one point: <em>{{ items.$count('points==1') }}</em></p>
<p>Number of items which have more than one point: <em>{{items.$count('points&gt;1')}}</em></p>
</pre>
<pre class="doc-scenario">
it('should calculate counts', function() {
expect(binding('items.$count(\'points==1\')')).toEqual(2);
expect(binding('items.$count(\'points>1\')')).toEqual(1);
});
it('should recalculate when updated', function() {
using('.doc-example-live li:first-child').input('item.points').enter('23');
expect(binding('items.$count(\'points==1\')')).toEqual(1);
expect(binding('items.$count(\'points>1\')')).toEqual(2);
});
</pre>
</doc:example></div>
</div>