SlicePipe class
Creates a new List or String containing a subset (slice) of the elements.
Usage
expression | slice: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.
- a positive integer: return the item at
- 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 ['a', 'b', 'c', 'd'] | slice:1:3">{{i}}</li>
</ul>
<pre>
{{str}}[0:4]: '{{str | slice:0:4}}' --> 'abcd'
{{str}}[4:0]: '{{str | slice:4:0}}' --> ''
{{str}}[-4]: '{{str | slice:-4}}' --> 'ghij'
{{str}}[-4:-2]: '{{str | slice:-4:-2}}' --> 'gh'
{{str}}[-100]: '{{str | slice:-100}}' --> 'abcdefghij'
{{str}}[100]: '{{str | slice:100}}' --> ''
</pre>
The first example generates two <li>
elements with text b
and c
.
The second example uses the string 'abcdefghij'
.
- Implemented types
- Annotations
- @Pipe('slice', pure: false)
Constructors
Properties
- hashCode → int
-
The hash code for this object. [...]
read-only, inherited
- runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed. [...]
inherited
-
supports(
dynamic obj) → bool -
toString(
) → String -
Returns a string representation of this object.
inherited
-
transform(
dynamic value, int start, [int end]) → dynamic
Operators
-
operator ==(
Object other) → bool -
The equality operator. [...]
inherited