SlicePipe

export class SlicePipe

exported from angular2/common defined in angular2/src/common/pipes/slice_pipe.ts (line 5)

Creates a new List or String containing only a subset (slice) of the elements.

The starting index of the subset to return is specified by the start parameter.

The ending index of the subset to return is specified by the optional end parameter.

Usage

expression | slice:start[:end]

All behavior is based on the expected behavior of the JavaScript API Array.prototype.slice() and String.prototype.slice()

Where the input expression is a [List] or [String], and start is:

and where end is:

When operating on a [List], the returned list is always a copy even when all the elements are being returned.

List Example

This ngFor example:

@Component({ selector: 'slice-list-example', template: `<div> <li *ngFor="var i of collection | slice:1:3">{{i}}</li> </div>` }) export class SlicePipeListExample { collection: string[] = ['a', 'b', 'c', 'd']; }

produces the following:

<li>b</li>
<li>c</li>

String Examples

@Component({ selector: 'slice-string-example', template: `<div> <p>{{str}}[0:4]: '{{str | slice:0:4}}' - output is expected to be 'abcd'</p> <p>{{str}}[4:0]: '{{str | slice:4:0}}' - output is expected to be ''</p> <p>{{str}}[-4]: '{{str | slice:-4}}' - output is expected to be 'ghij'</p> <p>{{str}}[-4:-2]: '{{str | slice:-4:-2}}' - output is expected to be 'gh'</p> <p>{{str}}[-100]: '{{str | slice:-100}}' - output is expected to be 'abcdefghij'</p> <p>{{str}}[100]: '{{str | slice:100}}' - output is expected to be ''</p> </div>` }) export class SlicePipeStringExample { str: string = 'abcdefghij'; }

Annotations

@Pipe({name: 'slice', pure: false})

@Injectable()


Members

transform(value: any, args?: any[]) : any

Not Yet Documented

supports(obj: any) : boolean

Not Yet Documented