Piotr Sikora - Logo - Automatyzacja procesów | AI | JavaScript | Front End | Team Leader
  • Home
  • Services
    • Process Automation
    • AI for Lawyers
    • Holded Automation
  • Blog
  • Quotes
  • Contact
PL/EN

Angular 2 - How to pass more parameters to Pipe

  • Home
  • Blog
  • Angular 2 - How to pass more parameters to Pipe
Angular 2 - How to pass more parameters to Pipe

By Piotr Sikora

  • angular

  • 3 min read

Table of Contents

  • Pass a string as a parameter
  • Pass array as a parameter
  • Pass object as a parameter
  • Also about Angular:

Pipes are very important element of Angular 2 framework. With it you can transform and filter your data. But how can you deal with it?

Lets start with a simple definition of pipe which filters data:

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

@Pipe({
    name: 'filterData',
    pure: false
})

export class FilterData implements PipeTransform {
    transform(items:any[], args:string[]):any[] {
        if (typeof items === 'object') {
            var resultArray = [];
            if (args.length === 0) {
                resultArray = items;
            }

            else {
                for (let item of items) {
                    if (item.name != null && item.name.match(new RegExp(''+args, 'i'))) {
                        resultArray.push(item);
                    }
                }
            }

            return resultArray;
        }
        else {
            return null;
        }

    }

}

This pipe will filter your data and as a filtering parameter will get an param passed as a args:string[]. So easily when you want to add text input which will be a filtering string you need to connect it with your pipe in component like this:

<input type="text" #filter (keyup)="0">

Now when you want to filter your data by string passed into input you need to get a value of #filter element like this (filter.data):

<div class="row" *ngFor="let point of (points | filterData: filter.value">

Pass a string as a parameter

To pass more parameters to your Pipe you will need to change a little your Pipe definition:

export class FilterData implements PipeTransform {
transform(items:any[], args:string[], additionl):any[] {
console.log(additionl);

So as you can see you are just passing new parameter to your Pipe. Now when you want to pass it from your template you need to add it like it is in example:

<div class="row" *ngFor="let point of (points | filterData: filter.value : 'name')">

After it you will see that passed parameter 'name' will be displayed in your console.

Pass array as a parameter

But what if you want to pass an array of elements? It is possible too! You can do this like this without changing your Pipe definition.

<div class="row" *ngFor="let point of (points | filterData: filter.value : ['all','name'])">

Pass object as a parameter

Yes you can pass an object as a parameter to your pipe. You cannot be limited in case you want to pass more than one parameter - you can pass an object of parameters too. To do that you can just do it from template of your component as it is described in code example:

<div class="row" *ngFor="let point of (points | filterData: filter.value : {name: true})">

So this can be a base to extend your pipes! You dont need to base it on one passed element!

Also about Angular:

  1. State management and Side Effects (@effect) in NgRx

  2. Angular 2 – Pipes (TypeError: Cannot read property ‘length’ of undefined)

Tags:

    #angular

    #javascript

    #js

    #pipe

Comments

Categories

after-hours(1)AI(9)ai-en(1)angular(4)automatic-tests(1)Automation(2)cryptography(1)css(8)CyberSecurity(2)Development(7)DevOps(1)events(3)javascript(11)n8n(31)ollama(1)security(2)seo(1)

Recent Posts

Prompting workshop at IdeaLab in Kielce — participants working at a laptop

AI

Effective Prompting — a Workshop for Young People at IdeaLab in Kielce

OCR in n8n for Multiple Receipts and Invoices at Once — Saving to Google Sheets

n8n

OCR in n8n for Multiple Receipts and Invoices at Once — Saving to Google Sheets

Checking Variable Values in n8n: IF vs SWITCH

n8n

Checking Variable Values in n8n: IF vs SWITCH

Automate Your Gmail with n8n — AI-Generated Reply Drafts with an LLM

n8n

Automate Your Gmail with n8n — AI-Generated Reply Drafts with an LLM

n8n: ZPE Lesson Generator — from URL to a Complete Lesson in 90 Seconds

n8n

n8n: ZPE Lesson Generator — from URL to a Complete Lesson in 90 Seconds

About Me

Piotr Sikora - Process Automation | AI | n8n | Python | JavaScript

Piotr Sikora

Process Automation Specialist

I implement automation that saves time and money, streamlines operations, and increases the predictability of results. Specializing in process automation, AI implementation, and workflow optimization using n8n, Python, and JavaScript.

n8n Workflows

n8n workflow automation templates

Explore my workflow templates on n8n. Ready-to-use automations for blog management, data collection, and AI-powered content processing.

3Workflow Templates
View Templates

• Auto-Categorize Blog Posts with AI

• Collect LinkedIn Profiles

• Export WordPress Posts for SEO

Tags

activepiecesafter-hoursahrefsaiai agentsai automationAI cost reductionai in educationai securityangularanonymizationantigravityapiAqua Securityarcade-gamesarchitectureautomationbackendbest-practicesbielik
“If somebody offers you an amazing opportunity but you are not sure you can do it, say 'yes' – then learn how to do it later!”
Richard Branson
View more quotes

Similar Articles

Discover more related content

DevMeeting Angular 2: Exploring the Future

DevMeeting Angular 2: Exploring the Future

My recap of the DevMeeting Angular 2.0 workshop in Krakow, a one-day event where developers learn the basics of a new framework together in a group.

Fix Angular 2 Pipes: Resolve TypeError

Fix Angular 2 Pipes: Resolve TypeError

How I fixed the TypeError Cannot read property length of undefined error in an Angular 2 pipe by handling data that is undefined when filtering a list.

Angular Side Effects with @Effect & NgRx CRUD

Angular Side Effects with @Effect & NgRx CRUD

Essential CRUD Snippets. Angular is giving great tools to build application and NgRx gives you opportunity to manage you app with state.

Piotr Sikora | ai | n8n | javascript | python

Let's get to know each other!

Get in touch with me
Piotr Sikora | Process Automation  | AI Implementation 🤖 | Technology Consulting
Quick links
  • Home
  • Blog
  • Contact
Contact
  • piotr.sikora.ck@gmail.com
  • +48 505 684 661

© Piotr Sikora 2026 | All Rights Reserved