forked from angular/code.angularjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular.Array.limitTo.html
45 lines (43 loc) · 2.08 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
44
45
<h1>angular.Array.limitTo</h1>
<div class="angular-array-limitto"><h2>Description</h2>
<div class="description"><p>Creates a new array containing only a specified number of elements in an array. The elements
are taken from either the beginning or the end of the source array, as specified by the
value and sign (positive or negative) of <code>limit</code>.</p>
<p>Note: This function is used to augment the <code>Array</code> type in Angular expressions. See
<a href="#!/api/angular.Array"><code>angular.Array</code></a> for more information about Angular arrays.</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 <code>limit</code> number is
positive, <code>limit</code> number of items from the beginning of the source array are copied.
If the number is negative, <code>limit</code> number of items from the end of the source array are
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>