Trimming a String via a Pipe in Angular
Let's learn how to use the SlicePipe channel. This channel allows you to trim a string. It accepts parameters that specify the start and end indexes of the cut. To pass a parameter, put a colon after the channel name and list the parameters.
Let's look at an example. In the component class, we set the property name:
export class AppComponent {
name: string = 'john';
}
Now, using the SlicePipe channel, we'll trim the string, specifying the start and end indexes for it:
<div>
{{ name | slice:0:2 }}
</div>
The result will be as follows:
<div>
jo
</div>
Create a string of 11 characters. Print the segment from 2 to 4 index.