Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8912059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:06:20+00:00 2026-06-15T04:06:20+00:00

Say I have an ng-repeat with a big array. When ng-repeat runs, it adds

  • 0

Say I have an ng-repeat with a big array.

When ng-repeat runs, it adds every element of that array to an isolated scope, as well as having the array itself in a scope. That means that $digest checks the entire array for changes, and on top of that, it checks every individual element in that array for changes.

See this plunker as an example of what I’m talking about.

In my use case, I never change a single element of my array so I don’t need to have them watched. I will only ever change the entire array, in which case ng-repeat would re-render the table in it’s entirety. (If I’m wrong about this please let me know..)

In an array of (say) 1000 rows, that’s 1000 more expressions that I don’t need evaluated.

How can I deregister each element from the watcher while still watching the main array?

Perhaps instead of deregistering I could have more control of my $digest and somehow skip each individual row?

This specific case is actually an example of a more general issue. I know that $watch returns a ‘deregisteration’ function, but that doesn’t help when a directive is registering the watches, which is most of the time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:06:21+00:00Added an answer on June 15, 2026 at 4:06 am

    To have a repeater with a large array that you don’t watch to watch every item.

    You’ll need to create a custom directive that takes one argument, and expression to your array, then in the linking function you’d just watch that array, and you’d have the linking function programmatically refresh the HTML (rather than using an ng-repeat)

    something like (psuedo-code):

    app.directive('leanRepeat', function() {
        return {
            restrict: 'E',
            scope: {
               'data' : '='
            },
            link: function(scope, elem, attr) {
               scope.$watch('data', function(value) {
                  elem.empty(); //assuming jquery here.
                  angular.forEach(scope.data, function(d) {
                      //write it however you're going to write it out here.
                      elem.append('<div>' + d + '</div>');
                  });
               });
            }
        };
    });
    

    … which seems like a pain in the butt.

    Alternate hackish method

    You might be able to loop through $scope.$$watchers and examine $scope.$$watchers[0].exp.exp to see if it matches the expression you’d like to remove, then remove it with a simple splice() call. The PITA here, is that things like Blah {{whatever}} Blah between tags will be the expression, and will even include carriage returns.

    On the upside, you might be able to just loop through the $scope of your ng-repeat and just remove everything, then explicitly add the watch you want… I don’t know.

    Either way, it seems like a hack.

    To remove a watcher made by $scope.$watch

    You can unregister a $watch with the function returned by the $watch call:

    For example, to have a $watch only fire once:

    var unregister = $scope.$watch('whatever', function(){ 
         alert('once!');
         unregister();
    });
    

    You can, of course call the unregister function any time you want… that was just an example.

    Conclusion: There isn’t really a great way to do exactly what you’re asking

    But one thing to consider: Is it even worth worrying about? Furthermore is it truly a good idea to have thousands of records loaded into dozens of DOMElements each? Food for thought.


    EDIT 2 (removed bad idea)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a SSI script that uses exec, or a PHP script that
Say I have an array: $myArray = array(foo, bar); What is a good way
Let's say I have an array of floating point numbers, in sorted (let's say
Let's say I have a 3rd table that stores data from two other tables...
Let say I have 5 small piece of codes in C. Every time I
Say I have function with_foo that takes a block, and wrap it around a
Say I have a <div> like this that is going to have all of
I have this big problem that i dont know how to fix. I have
Say I have the text abcabx. I would like to know that there is
Say I have a factory method that churns out instances of type T, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.