Piotr Sikora - Logo - Automatyzacja procesów | AI | JavaScript | Front End | Team Leader
  • Home
  • Services
    • Process Automation
    • AI for Lawyers
  • 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)

Share this article

TwitterLinkedInFacebook

Tags:

  • #angular

  • #javascript

  • #js

  • #pipe

Categories

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

Recent Posts

Testing Kimi Code: First Impressions from Web and CLI

Development

Testing Kimi Code: First Impressions from Web and CLI

Why You Shouldn't Cram Multiple Webhooks Into One n8n Workflow

Automation

Why You Shouldn't Cram Multiple Webhooks Into One n8n Workflow

DRY, WET, AHA: Finding the Right Balance in Code Reuse

Development

DRY, WET, AHA: Finding the Right Balance in Code Reuse

API vs Webhook: Understanding the Difference

Development

API vs Webhook: Understanding the Difference

RTCROS Framework: Structure Your Prompts for Better AI Results

AI

RTCROS Framework: Structure Your Prompts for Better AI Results

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 cost reductionai-agentsai-automationangularantigravityapiAqua Securityarcade-gamesarchitectureautomationbackendbest-practicescadillacs-and-dinosaurschatbotchatgptCI/CD
“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

Last weekend Ive been with my friends at DevMeeting about Angular 2.0 in Krakow.

Fix Angular 2 Pipes: Resolve TypeError

Fix Angular 2 Pipes: Resolve TypeError

Ive been trying to build simple filtering in application -> Show-ur-bugs

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