Custom Pipe creates a mesmerizing infinite loop effect on images (blinking)

I have some data that needs to be displayed and it looks like this:

https://drive.google.com/open?id=1Od-QC4xpfXXH4UgKDPkhkB90DQMUDAhV

Here is the code snippet:

<ion-grid *ngFor="let item of content | sortprogram: 'month'">
   <ion-item>{{item.key}}</ion-item>
   <ion-row>
      <ion-col col-3 col-md-4 col-xl-12 *ngFor="let content of item.value | slice:0:limit; let i=index">
         <img (click)="goView(content)" src="{{content.thumbnail_image}}" />
      </ion-col>
   </ion-row>
</ion-grid>

The issue I'm facing is that it keeps looping on images due to a custom pipe.

How can I prevent this endless looping?

I am using a groupby pipe. However, when I remove the custom pipe, everything works fine.

Below are my groupby pipes:

transform(value: Array<any>, field: string): Array<any>{ 

    if(!value || !value.length) { return value; } 

    const groupedObj = value.reduce((prev, cur)=> { 

        if(!prev[cur[field]]) { 
            prev[cur[field]] = [cur]; 
        } else { 
            prev[cur[field]].push(cur); 
        } return prev; 

    }, {}); 

    return Object.keys(groupedObj).map(key => ({ key, value: groupedObj[key] 

}));

Answer №1

To enhance code readability, it is suggested to avoid using the same object name multiple times. In this case, the name content appears twice which might be causing confusion. One way to address this issue is by replacing one instance of content with a different name such as element. Please review and make necessary adjustments.

<ion-grid *ngFor="let item of content | sortprogram: 'month'">
    <ion-item>{{item.key}}</ion-item>
        <ion-row>
            <ion-col col-3 col-md-4 col-xl-12 
               *ngFor="let element of item.value | slice:0:limit; let i=index">
                <img (click)="goView(element)" src="{{element.thumbnail_image}}" />
            </ion-col>
        </ion-row>
</ion-grid>

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

Guide to forming an array by extracting specific properties from a nested JSON array using javascript

Currently, I have this list: list = { id: 1, arr: [ {index : 1 , description: "lol" , author: "Arthur"}, {index : 2 , description: "sdadsa" , author: "Bob"}, {index : 3 , desc ...

There seems to be a mismatch in this Typescript function overloading - None of the over

Currently, I am in the process of developing a function that invokes another function with enums as accepted parameters. The return type from this function varies depending on the value passed. Both the function being called (b) and the calling function (a ...

How can I run a TypeScript function within a JavaScript file?

I am working with a typescript file named file1.ts export function Hello(str: string) { console.log(str); } In addition, I have another file called index.js { require('./some.js'); } Furthermore, there is a script defined in the pack ...

Automatically activate the Focus Filterfield in the ng-multiselect-dropdown upon clicking

I've integrated the ng-multiselect-dropdown package into my Angular project using this link: https://www.npmjs.com/package/ng-multiselect-dropdown. Everything is functioning as expected, but I'm looking to automatically focus on the filter input ...

TS - Custom API hook for making multiple API requests - incompatible type with 'IUseApiHook'

What is my objective? I aim to develop a versatile function capable of handling any type of API request for a frontend application. Essentially, I want to add some flair. Issue at hand? I find myself overwhelmed and in need of a fresh perspective to revi ...

In Ionic 3, the term "Twilio" is not recognized

Attempting to integrate Twilio into my Ionic 3 application has been a bit of a challenge. While it works fine when tested on a browser, running it on an actual device led to a frustrating error message: TypeError: undefined is not a function {stack: (...), ...

Getting a specific array from the API with fetch in Angular: A step-by-step guide

I am trying to retrieve images from an API, but I'm having trouble accessing all the arrays to get to the data. Currently, I am only able to fetch the posts arrays in a single call and not beyond that. https://i.stack.imgur.com/aFWlD.jpg My method fo ...

Discover the outcome of clicking on an object (mock tests)

I am just starting out with React and I'm unsure about when to use mocking. For instance, within the 'ListItem' component, there is a 'click me' button that reveals a dropdown for 'cameras'. Should I focus on testing what ...

In the latest version of Angular, accessing document.getelementbyid consistently returns null

I am struggling with a component that looks like this export class NotificationPostComponent extends PostComponent implements OnInit, AfterViewInit { commentsDto: IComment[] = []; commentId = ''; ngOnInit(): void { this.route.data ...

TYPESCRIPT: The argument labeled as 'typeof X' cannot be assigned to the parameter labeled as 'Y' that extends

As I venture into coding with TypeScript, I am encountering some compilation issues. It appears that I am facing a hierarchy problem with several classes. The first class (A) defines a set of properties/functions. The second class (B) inherits from class ...

Refine the search results by focusing on a specific property value

Assume I have a type defined as follows: type Result = {error:true,response: undefined} | {error:undefined, response:{nick:string}} This type will either contain an error property or a response, but not both. Now, I am attempting to create a function tha ...

Encountered an error with Aurelia webpack 4 when trying to load a necessary CSS file during runtime

I encountered a unique issue with webpack and aurelia that I can't seem to figure out. After creating a new webpack configuration based on online resources and official documentation, the compilation goes smoothly without any errors. However, during r ...

Generics in Typescript interfaces

I'm trying to grasp the meaning of T = {} within this TypeScript interface. I've searched for documentation on this usage but haven't found anything specific. How does it differ from simply using T? interface CustomProps<T = {}> { ...

"Enhance your forms with RadixUI's beautiful designs for

New to Radix UI and styling components, I encountered difficulties while trying to adapt a JSX component to Radix UI: Utilizing Radix UI Radio Groups, I aim to style my component similar to this example from Hyper UI with grid layout showing stacked conte ...

Unable to alter fxFlex property within Component using "setAttribute('fxFlex', '25%')" does not function properly in Angular 6

Currently, I am utilizing the flexLayout module to create responsive divs in my Angular application. You can find more information about flexLayout at https://github.com/angular/flex-layout and also at https://alligator.io/angular/flex-layout/. const nav ...

Angular XOR operation between two strings

I need to perform XOR operation on two strings and I found a python implementation for it: def sxor(s1,s2): return ''.join(chr(ord(a) ^ ord(b)) for a,b in zip(s1,s2)) In the code above, a for loop is used to iterate over the strings and ...

The Extended Date type is indicating that the function cannot be located

I came across this helpful gist with date extensions: https://gist.github.com/weslleih/b6e7628416a052963349494747aed659 However, when attempting to use the functions, I encountered a runtime error stating: TypeError: x.isToday is not a function I foun ...

Error notifications continue to appear despite the presence of data in the input field

I am utilizing a component to exhibit various information (such as first name, last name, phone number, etc.) fetched from the API. The main focus is on executing CRUD operations, particularly the update operation. Referencing the image below: https://i ...

Restrain a Key according to the data type of its value within a universal category

I am currently working on creating a versatile function where the generic type is used to define its parameter. Here's an excerpt from this parameter : type Configuration<T> = { masterdata: T[], target: ???? } I am encountering difficu ...

An issue arises in Slate.js when attempting to insert a new node within a specified region, triggering an error

A relevant code snippet: <Slate editor={editor} value={value} onChange={value => { setValue(value); const { selection } = editor; // if nothing is currently selected under the cursor if (select ...