Troubleshooting slow performance with Angular's mat-checkbox

I am facing an issue with a mat-list that contains a mat-checkbox next to each list item. The list is quite large, around 700-800 elements long. There seems to be a significant delay between clicking the checkbox and seeing the check-mark appear. I suspect Angular is iterating through all elements even if only one is being changed due to change detection. However, I am unsure of how to resolve this issue.

<mat-list>
    <mat-list-item *ngFor="let listItem of productList">    
        <span (click)="selectProduct(listItem)">
            <div matLine>{{listItem.name}}</div>
            <div matLine>{{listItem.desc}}</div>
        </span>
        <mat-checkbox class="example-margin check-box" name="listItem.name" [(ngModel)]="listItem.checked"></mat-checkbox>
        <mat-divider></mat-divider>
        </mat-list-item>
</mat-list>

UPDATE

The issue was resolved by using ChangeDetectorRef and calling .detectChanges() whenever a click event occurs.

Answer №1

I have created a customized code snippet with 700 mat-checkboxes for you. Surprisingly, it only takes a fraction of a second to respond when clicked using Chrome version 73.0.3683.86. Although there is room for improvement in terms of speed, the primary focus of angular material has always been centered around enhancing user interface rather than just performance.

For an example, check out the code here.

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

Should I use Object.assign or define class properties?

Currently in the process of developing an angular application that interacts with the twitch API. The API returns data in various formats, some of which I need to parse and save into specific classes. My main concern is understanding the potential drawbac ...

Difficulties arise while trying to render the initial frame of a ThreeJS application

When I render the initial frame of my ThreeJS app, it significantly impacts performance. This causes freezing for 5 seconds in Edge and IE 11 browsers, with a popup stating "This window is not responding", which can be alarming to users. After using Chrom ...

Is it possible to automatically set focus on the input box in an html tag multiple times instead of just once with autofocus?

Currently, I am developing an online editor that allows users to quickly edit individual words. My approach involves replacing specific words with input boxes containing the word for direct editing by users. In order to streamline the process and ensure e ...

Generating a dynamic sub-navigation: A step-by-step guide

Currently delving into Angular 4 and exploring the clarity design system. Has anyone successfully tried implementing a subnav with dynamic links? Check out this link I'm a bit uncertain about the correct approach for achieving this. Any tips or insi ...

Utilizing Lazy Loading Modules within an Angular 2 (v5) App

I'm struggling to implement lazy loading in my Angular 2 (version 5.1.3) project. While following Todd Motto's guide on Lazy Loading Code Splitting, I am hitting a roadblock in getting it to function correctly. My app consists of multiple modul ...

Use a mock HTTP response instead of making an actual server call in Angular 4

I am facing a scenario where I have a function myFunc() that I subscribe to. When this function is called with X parameter, I expect a regular HTTP response from the server. However, if it is called without the X parameter, I want it to return a 'mo ...

Guide to implementing a Page Object Model for improved debugging of Protractor tests

Introduction I am on a mission to streamline my e2e testing code using the Page Object Model for easier maintenance and debugging. My Approach When embarking on creating end-to-end tests with Protractor, I follow these steps to implement the Page Object ...

What is the process for subscribing to the output of a flatMap operation?

Is there a way to subscribe to the result of flatMap in this code block? timer(0, 2000) .pipe( flatMap(() => this.scannerService.scan(this.scanType)), takeWhile(res => res.errorDesc !== "SUCCESS") ) .subscrib ...

Using Angular services in a lazily loaded module

There is a service named routing.service that subscribes to routing events and updates the Translate service when a parameter changes. The constructor code looks like this: this.router.events.subscribe(val => { if (val instanceof ActivationEnd ) { ...

How can I enable automatic completion of material components in vscode?

I'm currently following along with a tutorial on YouTube where the author demonstrates how VSCode autocompletes custom material elements when he hits return. However, I am not experiencing the same autocomplete feature when I type and hit return. How ...

The function signature '(priority1: number, priority2: number) => number' cannot be assigned to the parameter type '(a: unknown, b: unknown) => number'

I encountered the following type error (TypeScript - 3.7.5). Error TS2345: Argument of type '(priority1: number, priority2: number) => number' is not assignable to parameter of type '(a: unknown, b: unknown) => number'. Typ ...

Tips on sorting through and displaying specific data for editing within an Angular framework

const arr = [ 'code1', 'code2', 'code3', 'code4', 'code5' ]; const data = [ { device: 'code1' }, { device: 'code2' } ]; const codeList = data.map((x: any) => x.device); ...

Guide on bringing a function or its result from TypeScript (.ts) to JavaScript (.js)

I am working with a TypeScript file named a.component.ts import { Injectable } from '@angular/core'; import { HttpClientModule } from '@angular/common/http'; import { HttpClient } from '@angular/common/http'; @Injectable({ ...

Issues encountered while developing a ReactJS application using TypeScript

While attempting to create a React app using the command npx create-react-app client-app --use-npm --typescript, I expected to generate a project with TypeScript files, but instead ended up with index.js and app.js rather than index.tsx and app.tsx. Could ...

Tips for organizing content within a book chapter and sections within a meticulously structured database

Can you identify the issue with the function below? How would you suggest fixing it? list() { return this.bookRepo.all().then(books => Promise.all(books.map(book => Promise.all([ this.bookRepo.contents(book.id), ...

Angular: Setting the input field back to its original default value

In this scenario, the goal is to reset an input field back to its default value, even after a user manually changed the input value. However, the issue lies in the fact that the default value remains static and does not update, rendering the reset function ...

Angular app unit tests encountering issues due to Keycloak role-based redirection mechanism

In my Angular application, I needed to redirect users to either /route1 or /route2 based on their role. However, Keycloak only allows for a single route to be specified after logging in (in this case, route1). To solve this routing dilemma, I implemented t ...

Array of Angular FormGroup

I am facing an issue with setting data to the form array in my project. The scenario is that when filling out user details, some users have multiple addresses. Here is User.ts export interface User { id?: number; name: string; age: number; address ...

Tips for solving a deliberate circular dependency in an angular provider

If the existing injection token for this provider is available, I want to use it. Otherwise, I will use the specified provider. Below is the code snippet: providers: [ { provide: DesignerRecoveryComponentStore, useFacto ...

Issue encountered when working with Next Auth and TypeScript: The argument type 'string | undefined' cannot be assigned to the parameter type 'string | Buffer'

Encountering a TypeScript error that states: "Argument of type 'string | undefined' is not assignable to parameter of type 'string | Buffer'." An attempt to integrate NextAuth into a Next.js 14 application and configure logi ...