angular.Array.limitTo

Description

Creates a new array containing only the first, or last limit number of elements of the source array.

Note: this function is used to augment the Array type in angular expressions. See angular.Array for more info.

Usage

angular.Array.limitTo(array, limit);

Parameters

Returns

{Array}

A new sub-array of length limit.

Example

<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> it('should limit the numer array to first three items', function() { expect(element('.doc-example 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]'); });