Troubleshooting issues with data filtering in the @Pipe

I am currently working on filtering data and displaying it in an HTML table. Below is the code I have written: In module.ts

import Register10Pipe = require("./register10/register10.pipe");
@NgModule({
    declarations: [
        Register10Pipe.FilterPipe
    ])

In my.pipe.ts

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

@Pipe({
    name: 'sectionGroup'
})

export class FilterPipe implements PipeTransform {
    transform(items: any[], field: number, value: number): any[] {
        if (!items) return [];
        return items.filter(it => (+it[field]) === (+value));
    }
}

In my.component.ts

    import { FilterPipe } from './register10.pipe';
export class MyComponent implements OnInit {
    filter: FilterPipe;
...... 

This is the HTML where the data should be rendered

    <ng-container *ngFor='let data1 of sectionList'>
        <tr>
            <td colspan="7">
                {{data1.name}}
                <button (click)="ArrRow($event)" style="float: right" id="{{data1.id}}">+</button>
            </td>
        </tr>
        <tr *ngFor="let data2 of (model.Register10Data | filter:'sectionGroup':data1.id); let dataIndex = index">
            <td>
                {{dataIndex}}
            </td>
        </tr>
    </ng-container>

The sectionList contains an array of objects like myObj{number:id, string:name}. I am extracting the ID from this array and attempting to filter the data retrieved from the server. I believe using @Pipe in Angular for this purpose would be appropriate. Although there are other methods available, I prefer this approach. However, I encountered an exception.

Unhandled Promise rejection: Template parse errors: The pipe 'filter' could not be found (" ]*ngFor="let data2 of (model.Register10Data | filter:'sectionGroup':data1.id); let dataIndex = index">"): e@68:20 ; Zone: ; Task: Promise.then ; Value: Error: Template parse errors: The pipe 'filter' could not be found (" ]*ngFor="let data2 of (model.Register10Data | filter:'sectionGroup':data1.id); let dataIndex = index">"): e@68:20

Answer №1

Perhaps including parentheses around the property + filter will help?

<tr *ngFor="let entry of (model.Register10Data | filter:'sectionGroup':'cSectionId'); let dataIndex = index">
</tr>

Answer №2

Give this a try

 <ng-container *ngFor='let section of sectionList'>
    <tr>
        <td colspan="7" >{{section.name}}
            <button (click)="ArrRow($event)" style="float: right" id="{{section.id}}" >+</button>
        </td>
    </tr>
    <tr *ngFor="let data of (model.Register10Data | filter:'sectionGroup':section.id); let index = index">
        <td>
            {{index}}
        </td>
    </tr>
</ng-container>

You can reference the values from the first ngFor within the second one, but ensure you use distinct names like section and data in this context.

If you have not already done so, make sure to import your custom pipe in app.module.ts

...
import { FilterPipe } from './filter.pipe';

@NgModule({
  imports: [
    ...,
  ],
  declarations: [
    ...,
    FilterPipe
  ],
})
export class MyModule { }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

CRUD operation: The DELETE method is invoked prior to the user's request

Upon opening the localhost:4200 app, I noticed an old delete request already present. Even when I try to use the new delete request by clicking the button, it gives me a 404 (Not Found) error. However, manually entering the URL into the search bar does del ...

Combine the fileReplacement property from two separate Angular configurations

When working with multiple angular configurations, I often combine them to create different builds. However, one issue I encounter is that the fileReplacements attribute from each configuration does not merge properly. Instead, the last configuration speci ...

Displaying the user's name on the menu: a simple tutorial

I have a {{user_name}} variable in my app.component.ts and I want to utilize it to display the user name obtained from local storage once the user logs in. However, the name only loads at the start of the app and I wish to refresh it after the user logs i ...

What is the best way to effectively use combinedLatestWith?

https://stackblitz.com/edit/angular-ivy-s2ujmr?file=src/app/country-card/country-card.component.html I am currently working on implementing a search bar in Angular that filters the "countries$" Observable based on user input. My approach involves creatin ...

The type 'Promise<void>' is lacking the properties that are required by the type

I am having difficulty understanding the error message that says: The type 'Promise<void>' is missing the following properties from type 'InventoryModel[]': length, pop, push, concat, and 28 more. TS2740 Below is my functional co ...

You are unable to declare an Angular component as an abstract class within a module

In my coding project, there is a fundamental component class known as BaseComponent with its unique markup referred to as <base-component-fun>. The structure of this component's markup looks like this: <div> ..Base markup </div> Thi ...

Troubleshooting a Pulumi script in Azure using Typescript and encountering difficulties with function writing

My background is in using terraform, but now I am trying out Pulumi/typescript for the first time. In my codebase, I have two files - index.ts and blob.ts. The create function in blob.ts is responsible for creating a storage account, resource group, blob ...

Failure of ngClass in Angular 7 due to the presence of multiple classes (spaces)

Many frontend frameworks have a practice of encapsulating their CSS styling by adding another class as a prefix. For example, in Bootstrap: btn btn-primary where btn is the prefix. If I were to conditionally apply this using [ngClass] in Angular, it woul ...

What is the process for deploying a .NET Core + Angular single page application to multiple environments?

After utilizing the Angular project template with ASP.NET Core in Visual Studio 2019, I developed an application that includes multiple environments: DEV, STG, and Production. Each environment corresponds to specific "appsettings.json" files for the .NET p ...

Angular app's Google Drive viewer fails to display a PDF file

I have embedded an iFrame in my Angular app to display a PDF file using the link "https://drive.google.com/viewerng/viewer?embedded=true&url=my.pdf". However, I am facing an issue where sometimes it successfully displays the PDF, while other times it d ...

Type guards do not work properly on a union of enum types in TypeScript

Recently delved into the concept of Type Guards Chapter within the realm of Typescript However, I encountered an issue where my basic type guards failed to differentiate a union of enums. Why is this happening? enum A { COMMA = ',', PLUS = & ...

Creating Child Components in Vue Using Typescript

After using Vue for some time, I decided to transition to implementing Typescript. However, I've encountered an issue where accessing the child's methods through the parent's refs is causing problems. Parent Code: <template> <re ...

Associated interfaces with typing, yet distinct mandatory attributes

I frequently come across this particular pattern while working with the API. It involves having an object that, based on a specified type, will have certain properties that are always required, some that are optional, and some that are only required for a ...

Is there a way to incorporate an "else" condition in a TypeScript implementation?

I am trying to add a condition for when there are no references, I want to display the message no data is available. Currently, I am working with ReactJS and TypeScript. How can I implement this check? <div className="overview-text"> < ...

Using Angular for Sign in with Apple integration

I have been working on integrating Sign in with Apple into an Angular website. The implementation process begins with adding to the index.html file. Then I created a service named apple-login-service.ts using scriptjs. Here is the code for the apple but ...

Encountered an execution policy error while trying to run the "yo office" command in the Yeoman office add-in generator

I was eager to use Yeoman to develop an Office add-in with Angular. After successfully installing the necessary tools such as Node.js, Angular, Yeoman, and generator-office in PowerShell, I attempted to run the following code: yo office Unfortunately, I e ...

Troubleshooting CORS errors in axios requests within a Next.js application

Encountering an issue while attempting to make an axios call to my API on a different localhost. How can this be resolved? The tech stack being used includes Next.js, TypeScript, and Axios. Below is the function which - although written poorly for testing ...

The system is unable to process the property 'items' due to a null value

When trying to access the properties of ShoppingCart, an error is encountered stating that Property item does not exist on type {}. The mistake made in the code is unclear and difficult to identify. shopping-cart.ts import { ShoppingCartItem } from &apos ...

Creating dynamic HTML in Angular 2 can be achieved by utilizing directives, data

I am interested in building an accordion feature in angular2 without needing to duplicate the structure each time it is used. Similar to how we can create plugins in jQuery and include HTML code, I would like to find a way to achieve this in Angular2. Ca ...

Troubleshooting Jasmine Unit Testing issues with the ng-select library

Recently, I integrated the ng-select component from Github into my Angular application without encountering any console errors during runtime. It functions as expected; however, issues arise when running unit tests with Jasmine. To incorporate NgSelectMod ...