⊗jsagPmPpSS 54 of 97 menu

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.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline