forked from angular/code.angularjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular.Array.limitTo.html
43 lines (41 loc) · 1.88 KB
/
angular.Array.limitTo.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
<h1>angular.Array.limitTo</h1>
<div class="angular-array-limitto"><h2>Description</h2>
<div class="description"><p>Creates a new array containing only the first, or last <code>limit</code> number of elements of the
source <code>array</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.limitTo(array, limit);</pre>
</div>
<h3>Parameters</h3>
<ul class="parameters"><li><code ng:non-bindable="">array – {Array} – </code>
<p>Source array to be limited.</p></li>
<li><code ng:non-bindable="">limit – {string|Number} – </code>
<p>The length of the returned array. If the number is positive, the
first <code>limit</code> items from the source array will be copied, if the number is negative, the
last <code>limit</code> items will be copied.</p></li>
</ul>
<h3>Returns</h3>
<div class="returns"><code ng:non-bindable="">{Array}</code>
– <p>A new sub-array of length <code>limit</code>.</p></div>
</div>
<h2>Example</h2>
<div class="example"><doc:example>
<pre class="doc-source">
<div ng:init="numbers = [1,2,3,4,5,6,7,8,9]">
Limit [1,2,3,4,5,6,7,8,9] to: <input name="limit" value="3"/>
<p>Output: {{ numbers.$limitTo(limit) | json }}</p>
</div>
</pre>
<pre class="doc-scenario">
it('should limit the numer array to first three items', function() {
expect(element('.doc-example-live input[name=limit]').val()).toBe('3');
expect(binding('numbers.$limitTo(limit) | json')).toEqual('[1,2,3]');
});
it('should update the output when -3 is entered', function() {
input('limit').enter(-3);
expect(binding('numbers.$limitTo(limit) | json')).toEqual('[7,8,9]');
});
</pre>
</doc:example></div>
</div>