Open In App

Angular10 SlicePipe

In this article, we are going to see what is SlicePipe in Angular 10 and how to use it.

SlicePipe is used to create an array containing a slice of the element.



Syntax:

{{ value | SlicePipe }}

NgModule: Module used by SlicePipe is:



Approach: 

Input value:

Parameters:

Example 1:

Filename: app.component.ts




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent {
    collection: string[] = ['geeks', 'for', 'geeks', 'gfg'];
  }

 

 

Filename: app.component.html




<ul>
  <li *ngFor="let i of collection | slice:0:3">{{i}}</li>
</ul>

 

 

Output:

 

 

Example 2:

 

Filename: app.component.ts




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent {
    collection: string[] = ['geeks', 'for', 'geeks', 'gfg'];
  }

 

 

Filename: app.component.html




<ol>
  <li *ngFor="let i of collection | slice:0:4">{{i}}</li>
</ol>

 

 

Output:

 

 


Article Tags :