ItSolutionStuff.com

Angular Slice Pipe Example | Slice Pipe in Angular

By Hardik Savani • May 2, 2024
Angular

Hi All,

In this post, we will learn angular slice pipe example. I’m going to show you about slice pipe angular example. This article goes in detailed on angular slice pipe. we will help you to give example of angular 8 slice pipe array example. Let's get started with angular 9 slice pipe string example.

In this tutorial i will provide you full example and how to use angular slice pipe with start and end parameter. you can use it in angular 6, angular 7, angular 8, angular 9, angular 10, angular 11, angular 12, angular 13, angular 14, angular 15, angular 16 and angular 17 application.

I am not going to explain more and more description but i will simply give you syntax and some small examples so you can easily use it in your application.

Syntax:

{{ value_expression | slice : start [ : end ] }}

start: You must have to pass start parameter as number. it will start from given number with string or array.

end: You is a optional parameter as number. it will end from given number with string or array.

Slice Pipe with Start Param

It will start from 2 key of the given array.

import { Component } from '@angular/core';

@Component({

selector: 'my-app',

template: `<div>

<p>{{ myArray | slice: 2 }}</p>

</div>`,

styleUrls: [ './app.component.css' ]

})

export class AppComponent {

name = 'Angular';

myArray = [0, 1, 2, 3, 4, 5, 6, 7, 8];

}

Output

2,3,4,5,6,7,8

Slice Pipe with Start and End Param

It will start from 2 key and end with 7 key of the given array.

import { Component } from '@angular/core';

@Component({

selector: 'my-app',

template: `<div>

<p>{{ myArray | slice: 2:7 }}</p>

</div>`,

styleUrls: [ './app.component.css' ]

})

export class AppComponent {

name = 'Angular';

myArray = [0, 1, 2, 3, 4, 5, 6, 7, 8];

}

Output

2,3,4,5,6

Slice Pipe with Start with Nagative

It will start from -2 key it means it will take key value from last end of array.

import { Component } from '@angular/core';

@Component({

selector: 'my-app',

template: `<div>

<p>{{ myArray | slice: -2 }}</p>

</div>`,

styleUrls: [ './app.component.css' ]

})

export class AppComponent {

name = 'Angular';

myArray = [0, 1, 2, 3, 4, 5, 6, 7, 8];

}

Output

7,8

Slice Pipe with Start and End with Nagative

It will start from 2 key and end with -3. it means it will take key value from last end of array.

import { Component } from '@angular/core';

@Component({

selector: 'my-app',

template: `<div>

<p>{{ myArray | slice: 2:-3 }}</p>

</div>`,

styleUrls: [ './app.component.css' ]

})

export class AppComponent {

name = 'Angular';

myArray = [0, 1, 2, 3, 4, 5, 6, 7, 8];

}

Output

2,3,4,5

Slice Pipe with Array

import { Component } from '@angular/core';

@Component({

selector: 'my-app',

template: `<div>

<div *ngFor="let item of myArray | slice:2:6"> {{item}}</div>

</div>`,

styleUrls: [ './app.component.css' ]

})

export class AppComponent {

name = 'Angular';

myArray = [0, 1, 2, 3, 4, 5, 6, 7, 8];

}

Output

2

3

4

5

Slice Pipe with String

import { Component } from '@angular/core';

@Component({

selector: 'my-app',

template: `<div>

<p>{{ myString | slice: 10:30 }}</p>

</div>`,

styleUrls: [ './app.component.css' ]

})

export class AppComponent {

name = 'Angular';

myString = "This is Angular Slice Pipe Example";

}

Output

gular Slice Pipe Exa

I hope it can help you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

šŸ“ŗ Subscribe on YouTube

We Are Recommending You

ā˜…

Angular Percent Pipe Example | Percent Pipe in Angular

Read Now →
ā˜…

Angular Decimal Pipe Example | Number Pipe in Angular

Read Now →
ā˜…

Angular Date Pipe Example | Date Pipe in Angular

Read Now →
ā˜…

Angular Currency Pipe Example | Currency Pipe in Angular

Read Now →
ā˜…

How to Use Angular Pipe in Component Class?

Read Now →
ā˜…

How to Pass Multiple Parameters to Pipe in Angular?

Read Now →
ā˜…

Angular Nl2br Pipe Example

Read Now →
ā˜…

How to Create Custom Pipe in Angular 9/8?

Read Now →