The ngfor loop seems to be caught in an endless cycle of continuously executing functions and

I am currently working on a sophisticated reporting solution.

Essentially, I have created a table using an ngFor loop where I have implemented certain conditions that allow the user to view details of a clicked element by expanding and collapsing it.

The issue lies in these conditions executing infinitely. What I require is for these conditions to only be checked once. The continuous checking of conditions is causing performance degradation of the UI.

Here is the code snippet:

<div class="row" style="position:relative; overflow: hidden; margin-bottom: 30px;" >
   <!-- Code here -->
</div>

Below are insights into the functions and conditions used:

1) checkColumnVisibiliy(col): This function is utilized to display specific columns based on local storage settings.

2) checkIfHaveMoreSplits(nextsplit): This function determines if a table row should be expanded or collapsed based on the availability of the next split.

3) convertToDecimals(number, decimal): Used to convert long integers into user-friendly numbers.

Your assistance would be greatly appreciated.

Answer №1

It is not recommended to use methods in your template, as each time Angular performs change detection, the method will be invoked frequently. Therefore, it is not an infinite loop but rather a repetitive call during each change detection cycle.

To prevent this issue, it is advisable to move the logic from methods into your component and utilize variables in the template instead.

Furthermore, as mentioned in the previous comments, always opt for

*ngIf="checkColumnVisibiliy('impressions')"
over
*ngIf="checkColumnVisibiliy('impressions') === true"
.

In your scenario, it would be more efficient to use a single model variable that can be set to true or false based on conditions. This approach will simplify your code usage.

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

Advantages of Using Constructor Parameter Initialization Over the new Keyword in Angular 5

Sample CODE 1 : import { Component,OnInit } from '@angular/core'; import {exampleClass} from './exampleClass' @Component({ selector: 'app-root', templateUrl: './app.component.html', styleU ...

Access the document within the Angular Material File Selection feature

I have implemented a Material file selection feature in my project. The code snippet below shows how I am doing it: <label for="uploadPicture" class="upload-file"> <mat-icon>add_a_photo</mat-icon> </label> <input type="file" ...

Escaping double quotes in dynamic string content in Javascript can prevent unexpected identifier errors

Need help with binding the login user's name from a portal to a JavaScript variable. The user's name sometimes contains either single or double quotes. I am facing an issue where my JavaScript code is unable to read strings with double quotes. ...

Storing various checkbox values into a database

I have a form with checkboxes that I need to submit to an API for database storage. This is the city.page.html <ion-item *ngFor="let city of cities;"> <ion-checkbox [(ngModel)]="city.id" ></ion-checkbox> <i ...

Missing 'id' property in ngFor loop for object type

I'm currently learning Angular and I've been following a code tutorial. However, despite matching the instructor's code, it doesn't seem to be working for me. When I try to compile the following code, I receive an error message stating ...

Angular 4 has the capability to automatically log out in all tabs when a user logs out in one open tab

I am looking to implement a feature where I automatically log out from all open tabs when logging out from one tab. Currently, I am storing a jwt token in localStorage upon login and removing the token upon logout. Any suggestions on how I can utilize st ...

How to access the types of parameters in a function type

I am working on a function that takes a value and default value as arguments. If the value is a boolean, I want the return type to match the type of the default value. Here is the function I have: export type DetermineStyledValue<T> = ( value: str ...

Where does the browser retrieve the source files for "sourcemapped" JavaScript files from?

As I begin working on an existing project built with angular JS, upon opening chrome dev tools and navigating to the "source" view, a message appears: Source map detected... This prompts me to see a link to: https://i.stack.imgur.com/RZKcq.png The fi ...

Error arises when attempting to pass interface props to a component in a React Typescript application

I am currently delving into the world of React js and typescript. As part of my learning process, I have created a demo application that allows users to input their name and age. The app features an ErrorModal that should pop up on the screen whenever inco ...

"Optimize Your Data with PrimeNG's Table Filtering Feature

I'm currently working on implementing a filter table using PrimeNG, but I'm facing an issue with the JSON structure I receive, which has multiple nested levels. Here's an example: { "id": "123", "category": "nice", "place": { "ran ...

Interference with ElementClickInterceptedException in Selenium is caused by the presence of a WebPack iframe within an Angular application, despite implementing WebDriverWait

Everything was going smoothly with my automation code until suddenly, an ElementClickIntercepted exception started occurring when trying to click the "Sign In" button on the login screen: public class LoginPage { private readonly IWebDriver driver; ...

Tomcat serving Maven web app is unable to locate Angular's /assets/ directory

My web application built with Maven has a particular structure that includes directories like 'dist', 'errors', and 'WEB-INF' within the 'webapp' directory. The 'dist' folder specifically contains all of t ...

Expanding the Warnings of React.Component

When I create a new class by extending React.Component in the following manner: export default class App extends React.Component<any, any > { constructor (props: React.ReactPropTypes) { super(props); } // other code } I encountere ...

Disable editing of all form controls within a template-based form

We are looking to implement a 'read-only' feature for certain users in our template-based form that utilizes Angular Material controls such as matInput and mat-select. My initial approach was to check user privileges and then iterate through the ...

Can you explain the distinction between the fontawesome angular package, the standard npm package, and simple sass?

In my new Angular CLI project (version 8+) that is using Sass (SCSS), I have been exploring the Fontawesome documentation and discovered there are several methods for hosting Fontawesome icons. These include installing the npm package, integrating the angu ...

Guide to creating a universal interface using the generic class concept

I am in the process of developing a new augmented, generic interface that is based on an existing interface. The original interface sets out the properties that the object will possess (root). The enhanced type should also have these properties, but instea ...

How to Install Definitely Typed Packages in Visual Studio 2015 RC for AspNet5 with the Help of Gulp and TSD

Struggling to add angular.d.ts to my MVC6 project, I've hit a roadblock. Although I've configured Gulp to reinstall necessary packages using tsd, I'm stuck on the initial installation process. The instructions suggest running 'tsd inst ...

The Next.js 13 function getQueriesData does not have any matching overloads for TypeError

Having a TypeScript error issue while using the getQueriesData function in Next.js 13 with React Query. Below is my code snippet: // app/products.tsx import { getQueryClient } from "@/app/providers/getQueryClient"; import { useQuery, useQueryCli ...

Exploring different pages in Angular2 and Ionic2

I am encountering difficulties when it comes to navigating between pages in Angular2 / Ionic2. When attempting to navigate to a new page using the code below: import {Page, NavController} from 'ionic-angular'; import {HomePage} from '../ho ...

Is there a way to access the value of a public variable within the @input decorator of a function type?

I am working on a dropdown component that utilizes the @Input decorator to define a function with arguments, returning a boolean value. dropdown-abstract.component.ts @Input() public itemDisabled: (itemArgs: { dataItem: any; index: number }) => boo ...