SlicePipe class

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

Usage

$pipe.slice(expression, start, [end])

The input expression must be a List or String.

  • start: the starting index of the subset to return.
    • a positive integer: return the item at start index and all items after in the list or string expression.
    • a negative integer: return the item at start index from the end and all items after in the list or string expression.
    • if positive and greater than the size of the expression: return an empty list or string.
    • if negative and greater than the size of the expression: return entire list or string.
  • end: The ending index of the subset to return.
    • omitted: return all items until the end.
    • if positive: return all items before end index of the list or string.
    • if negative: return all items before end index from the end of the list or string.

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

Examples

<ul>
    <li *ngFor="let i of $pipe.slice(['a', 'b', 'c', 'd'], 1, 3)">{{i}}</li>
</ul>

<pre>
  {{str}}[0:4]:   '$pipe.slice(str, 0, 4)}}' --> 'abcd'
  {{str}}[4:0]:   '$pipe.slice(str, 4, 0)}}' --> ''
  {{str}}[-4]:    '$pipe.slice(str, -4)}}' --> 'ghij'
  {{str}}[-4:-2]: '$pipe.slice(str, -4, -2)}}' --> 'gh'
  {{str}}[-100]:  '$pipe.slice(str, -100)}}' --> 'abcdefghij'
  {{str}}[100]:   '$pipe.slice(str, 100)}}' --> ''
</pre>

The first example generates two <li> elements with text b and c. The second example uses the string 'abcdefghij'.

Annotations
  • @Pipe('slice', pure: false)

Constructors

SlicePipe()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
supports(dynamic obj) bool
toString() String
A string representation of this object.
inherited
transform(dynamic value, int start, [int? end]) → dynamic

Operators

operator ==(Object other) bool
The equality operator.
inherited