"Create a special pipe system to filter an empty array

After creating a custom pipe, I incorporated it into my project:

@Pipe({ name: 'orderBy' })
export class OrderByPipe implements PipeTransform {
     transform(items: any[], orderBy: string): any[] {
        if (items && items.length > 1) {
            console.log('items -> ', items);
        }
        console.log('return -> items -> ', items);
        return items;
     }
 }

Within a component, the pipe is utilized in this manner:

<tr *ngFor="let item of items | orderBy:'title'" class="myclass">

Despite the table rows showing up correctly, an issue arises where the length of the items array within the pipe always appears as zero. The console output upon returning from the pipe, however, indicates that the array is populated with objects. What could be causing this discrepancy?

Answer №1

To ensure proper execution, include parentheses as illustrated below. By doing this, the item will be passed to the tube and the outcome will return to the ngFor loop.

<tr *ngFor="let item of ( items | orderBy:'title')" class="myclass">

For more information, refer to the Official Angular Documentation. Look up "ngfor" for practical illustrations.

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

Changing the time format from hh:mm:ss to GMT in an Angular 2 application

Given Input:- Current time: 21:00:00 Desired Output:- Updated time: Wed Dec 20th, 2017 9:00pm GMT+0530 (IST) OR Updated time: 2017-12-20 21:00:00 ...

Guide to embedding one Angular application into another Angular application

I am looking to integrate two angular applications, A and B. Specifically, I want to display the entire application A within a tab in application B. How can I accomplish this task effectively? I would greatly appreciate any guidance on how to achieve this ...

In order to prevent redundancy in your Angular 2+ project, make sure to set

I recently organized my app by creating different modules such as auth, admin, and main. However, I noticed that I have the same imports in each module: import { RouterModule } from '@angular/router'; import { BrowserModule } from '@angul ...

Problem with rendering accordion list in Ionic 2

I am integrating an accordion feature into my Ionic2 application. Here is the code snippet from my component: export class ContactPage { public days : any[]; public shownGroup; constructor(public navCtrl: NavController) { this.days= ...

How to use the Angular 7 CLI in a programmatic way

My goal is to set up a server that can launch an Angular 7 app. Another scenario where this capability would be useful is for more advanced generation tasks, such as adding multiple files directly after generating an Angular project. const angularClient = ...

Error message: Injector Error: R3InjectorError(Standalone[_AppComponent])[_WebService -> _WebService -> _WebService] occurred

Being a student, I must apologize in advance for any mistakes in terminology or gaps in my understanding. I am currently developing an Angular front-end to communicate with my backend API. However, I keep encountering the following error in the web page c ...

CPU usage spikes after launching a Cordova project in Visual Studio 2015 RTM

If you're looking for the source code of the project, you can find it at https://github.com/Yaojian/Ionic-TypeScript-Starter/. I decided to create a Visual Studio project by forking https://github.com/Justin-Credible/Ionic-TypeScript-Starter/ and fol ...

Ways to implement logging in an NPM package without the need for a specific logging library

Currently, I am in the process of developing a company npm package using TypeScript and transferring existing code to it. Within the existing code, there are instances of console.log, console.warn, and console.error statements, as shown below: try { c ...

Angular Element utilizing Angular Universal

I am working on an Angular Universal app and facing issues while trying to load a web component that I created separately. I have concatenated all the JS files for the child app into one and attempted to use it in my parent app using a selector. However, t ...

State management at its core with integrated functionalities

I'm exploring different ways to manage application state within Angular 18 using its built-in features. Would it be effective to start with a simple service that utilizes dependency injection (DI)? As someone new to Angular 18, I'm a bit confuse ...

What is the significance of including the Angular component selector in HTML?

I'm brand new to Angular and html/html5, so please bear with me if my questions seem basic. I've included a screenshot below: https://i.sstatic.net/UXobT.png Here are the questions on my mind: Q1- The component selector name paproductform is n ...

The variable 'minSum' is being referenced before having a value set to it

const arrSort: number[] = arr.sort(); let minSum: number = 0; arrSort.forEach((a, b) => { if(b > 0){ minSum += minSum + a; console.log(b) } }) console.log(minSum); Even though 'minSum' is defined at the top, TypeScript still throws ...

Enhancing Google analytics integration with Continuous Integration (CI) in Angular 9

Currently, I am working on an app that is being developed on circleCI. Since updating Angular from version 7 to 9, there has been a prompt to install the CLI on circleCI. Google’s Privacy Policy at https://policies.google.com/privacy? For more details ...

Is it possible to create and manage a hierarchical menu in React (Next.js) using a generic approach?

Over the past few days, I've been working on a project involving a navigation bar built with TypeScript and React (Next.js). Up until now, I've only had a single level navigation, but now I'm looking to upgrade to a multi-level navigation me ...

Typescript: Assigning Variables Without Prior Declaration

In my upcoming Node.js application, I decided to use TypeScript for development. However, I encountered a perplexing issue while working on the code below: class AuthService { public async init(req: Request, res: Response) { let user: IUser | ...

Concealing Angular Features Using a Button

Currently, I am experimenting with Angular and attempting to create a button that disappears when clicked. Despite trying methods like [hidden], (click)="showHide = !showHide", and several others, nothing seems to be working as expected. This is the curre ...

Having trouble locating the reference to 'paypal' in a NextJS application when using PayPal's checkout.js?

I encountered an issue while utilizing PayPal checkout.js on my NextJS application. Below is the error message: Failed to compile. ./components/PaypalBtn.tsx:5:9 Type error: Cannot find name 'paypal'. 3 | 4 | useEffect(() => { > ...

Ways to update HTML values using Events

I am attempting to retrieve a value using Events (ionic) once it listens for my 'onSMSArrive' event. I am able to successfully retrieve the value from the events. However, I am encountering an issue where the value is not updating in my app. Bel ...

Applying Validators manually in Angular 2 beta 17

We are currently working on a legacy project that needs to be maintained until the final version with angular-final is deployed. Once we upgrade to the final version, I will be able to easily apply conditional Validators using: this.myForm.controls[&apos ...

Exploring Angular 4.3 Interceptors: A Practical Guide

I am currently working on a new app that needs authorization headers. Normally, I follow a similar approach to what is described in this article on scotch.io. However, I have recently learned that Angular 4 now fully supports HTTP Interceptors through the ...