How to Pass Multiple Parameters to Pipe in Angular?

How to Pass Multiple Parameters to Pipe in Angular?

In this post we will give you information about How to Pass Multiple Parameters to Pipe in Angular?. Hear we will give you detail about How to Pass Multiple Parameters to Pipe in Angular?And how to use it also give you demo for it if it is necessary.

In this post, i will give you example of angular pass multiple parameters to pipe. this example will help you pass multiple parameters to pipe angular. i would like to share with you how to pass multiple parameters to pipe in angular. This article goes in detailed on pass multiple values to pipe angular.

You can easily pass multiple arguments in pipe in angular 6, angular 7, angular 8 and angular 9 application.

In this example we will create ‘descPipe’ custom pipe and create dynamic description with multiple parameters. basically we will create “persons” array and print in table then using custom pipe that will create dynamic description.

You can see bellow simple solution and full example bellow:

Solution:

{{ person.desc | descPipe: 'arg1' : 'arg2' : 'arg3' }}

transform(desc: any, id: any, name: any, website: any): any {

return desc + ': ' + 'Your ID is ' + id + '. Your Name is ' + name + '. Your Website is ' + website + '.';

}

Example

src/app/desc-pipe.pipe.ts

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({

name: 'descPipe'

})

export class DescPipePipe implements PipeTransform {

transform(desc: any, id: any, name: any, website: any): any {

return desc + ': ' + 'Your ID is ' + id + '. Your Name is ' + name + '. Your Website is ' + website + '.';

}

}

Import Pipe: src/app/app.module.ts

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

import { BrowserModule } from '@angular/platform-browser';

import { FormsModule } from '@angular/forms';

import { AppComponent } from './app.component';

import { DescPipePipe } from './desc-pipe.pipe';

@NgModule({

imports: [ BrowserModule, FormsModule ],

declarations: [ AppComponent, DescPipePipe ],

bootstrap: [ AppComponent ]

})

export class AppModule { }

Update Component: src/app/app.component.ts

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

@Component({

selector: 'my-app',

templateUrl: './app.component.html',

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

})

export class AppComponent {

name = 'Angular';

persons = [

{

id: 1,

name: 'Hardik Savani',

gender: 'Male',

website: 'onlinecode',

desc: 'Your Info: ',

},

{

id: 2,

name: 'Kajal Patel',

gender: 'Female',

website: 'nicesnippets.com',

desc: 'Your Info: ',

},

{

id: 3,

name: 'Harsukh Makawana',

gender: 'Male',

website: 'laracode.com',

desc: 'Your Info: ',

}

]

}

Use Pipe in HTML: src/app/app.component.html

Also see:Angular nl2br Pipe Example

<h1>How to Pass Multiple Parameters to Pipe in Angular - ItsolutionStuff.com</h1>

<table border="1">

<tr>

<th>ID</th>

<th>Name</th>

<th>Website</th>

<th>Desc</th>

</tr>

<tr *ngFor="let person of persons">

<td>{{ person.id }}</td>

<td>{{ person.name }}</td>

<td>{{ person.website }}</td>

<td>{{ person.desc | descPipe: person.id : person.name : person.website }}</td>

</tr>

</table>

You can see bellow output:

I hope it can help you…

Hope this code and post will helped you for implement How to Pass Multiple Parameters to Pipe in Angular?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  52  =  60

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US