Optimizing Angular's ng-repeat for efficient updates by restricting the watch functionality to the relevant iteration

My task involves creating a table where users can edit certain fields in each row, which will impact other fields within the same row.

Due to this requirement, I cannot use bind-once for all the rendered data.

To address this issue, I attempted using the code snippet below:

<table class="table table-bordered table-condensed table-hover">
  <thead>
    <tr class="info">
      <th>Header</th>
      <th>Header</th>
      <th>Header</th>
      <th>Header</th>
    </tr>
  </thead>
  <tbody>
    <tr ng-repeat="a in alist">
      <td>{{::a.id}}</td>
      <td>{{::a.cod}}</td>
      <td>
        <input
          ng-model="a.sel"
          type="checkbox"
          class="input-sm"></input>
      </td>
      <td ng-if="a.sel">
        {{::a.desc}}
      </td>
      <td ng-if="!a.sel">
        "Other Content"
      </td>
    </tr>
  </tbody>

After testing, I observed that when a user checks or unchecks the a.sel checkbox, Angular will watch for changes in all angular {{vars}} on the page (excluding {{::vars}}).

If my understanding is correct (and hence explaining the slow performance with hundreds of rows loaded), how can I instruct Angular to only monitor changes within the specific row or ng-repeat iteration?

I am uncertain about the best approach to improve performance in this scenario. Any advice would be greatly appreciated.

Answer №1

To optimize performance, consider using the track by directive in AngularJS to specify which property should be used for evaluation:

<tr ng-repeat="item in itemList track by $index">

Alternatively, you can use:

<tr ng-repeat="item in itemList track by item.id">

For more information on this topic, refer to the official documentation for ng-repeat 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

Discovering the generic type from an optional parameter within a constructor

Looking to implement an optional parameter within a constructor, where the type is automatically determined based on the property's type. However, when no argument is provided, TypeScript defaults to the type "unknown" rather than inferring it as "und ...

The pinFileToIPFS method in Pinata IPFS is currently unable to accept files uploaded by users

Currently, I am immersed in a project where I am utilizing React.js, Express.js, and Node.js to transform a user-provided image into an NFT on the Ethereum blockchain. To achieve this, I must first upload the image to IPFS (Pinata being my choice of servic ...

deleting an object from an array in JavaScript

I have a collection of objects that looks like this: [{ "id": 2, "price": 2000, "name": "Mr Robot T1", "image": "http://placehold.it/270x335" }, { "id": 1, "price": 1000, "name": "Mr Robot T2", "image": "http://placehold.it ...

Coordinating a series of maneuvers

When it comes to coordinating multiple sequential actions in Redux, I find it a bit confusing. I have an application with a summary panel on the left and a CRUD panel on the right. My goal is to have the app automatically update the summary after a CRUD op ...

What is the best approach to dynamically implement useReducer in code?

Take a look at the repository here: https://github.com/charles7771/ugly-code In the 'Options' component, I am facing an issue where I am hardcoding different names for each reducer case instead of dynamically generating them for a form. This app ...

Modify the `div` content based on the selected items from the bootstrap dropdown menu

My navigation bar is built using Bootstrap and contains multiple drop-down items. Now I have another div with the class of col-md-3. Within this div, I would like to display the items of the dropdown menu when hovered over. Currently, hovering over a dro ...

Creating a jQuery multiple image preview feature is a simple and effective way to

Looking to implement a single image upload preview function in jQuery? Want to modify it to allow for multiple image uploads with separate boxes? Check out the HTML script below. <!DOCTYPE html> <html> <head> <title></title> ...

What is the best way to conceal a modal using jquery?

Click button to open modal: <button type="button" class="btn" onclick="CountClass()" runat="server" data-toggle="modal" data-target="#inlineForm1">OPEN</button> The modal code: <div class="modal fade text-left" id="inlineForm1" tabindex=" ...

Having trouble with displaying the modal dialog in Twitter Bootstrap 3?

There seems to be an issue with my Twitter Bootstrap modal as it is not rendering the dialog box correctly, and I'm puzzled about the reason behind this. HTML <p class="text-center btn-p"><button class="btn btn-warning" data-toggle="modal" ...

Why is URL Hash Navigation not functioning when linking to a different page's slide on the carousel?

Why isn't the #tag link being recognized? Even though the data-hash items are visible in the URL window, the script doesn't seem to pick them up. The standard script used on the carousel page is as follows: $(document).ready(function() { $( ...

Placement Mismatch of Radio Button in Form.Check Component of React-Bootstrap

Recently, I've been working on implementing a payment method feature where users can choose their preferred payment option using radio buttons. However, there seems to be an issue with the alignment of the button. Below is the code snippet I have so ...

AngularJS $log - display line numbers

When using angularjs $log in chrome, it displays the line as: angular.js:9037. I'm looking to have the line number where I actually call this method shown instead. (Displaying my js name and the correct line). Is there a way to achieve this since Angu ...

How to retrieve attributes of a model from a related model in Sails.js

Currently, I am utilizing the beta version(v0.10.0-rc3) of Sails.js and have updated the database adapter to PostgreSQL in order to enable associations via the Waterline ORM. My main focus is on creating a role-based user model for authorization based on d ...

A step-by-step guide on sending a fetch request to TinyURL

I have been attempting to send a post request using fetch to tinyURL in order to shorten a URL that is generated on my website. The following code shows how I am currently writing the script, however, it seems like it's not returning the shortened URL ...

What steps should I take to resolve the issue of my endpoint failing to accept POST requests?

I am in the process of developing a customized API, with an endpoint that is specified as shown below: https://i.stack.imgur.com/sZTI8.png To handle the functionality for this endpoint, I have set up a Profiling Controller. Inside my controller directory ...

Invoke a router inside Node.js once a route has been triggered

I am working with ExpressJS and integrating the Auth0 API for authentication, along with ReactJS on the client side. Due to some limitations of the Auth0 API that I discussed with their team, I have implemented a workaround where I send updated user detail ...

Smooth-scroll plugin does not activate active state (due to JS modification)

I'm currently facing an issue with a script that handles smooth scrolling and the active state on my main navigation. The plugin in question can be found at: It's important to note that the navigation bar is fixed and therefore has no height. T ...

Linked selection options for state, city, and postal code

I have set up a cascading dropdown list - State -> City -> Pincode . Instead of fetching data from the database, I am using JSON. The dropdown functions smoothly on the local server, but experiences slowness on the web server. Here is a snippet of ...

Credit for the Position swipejs

After integrating a swipeJS photo slideshow into my jQuery mobile application, I encountered an issue. I am trying to create points for counting the pictures similar to what is seen on this page: Although I have added the necessary HTML and CSS code to my ...

It's essential to ensure that this property remains responsive, whether through the data option or by initializing the property for class-based components

This code snippet contains the template and path information. <template> <div class=""> <c1 :text="message1"></c1> <c1 :text="message2"></c1> </div> </templa ...