Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>To have a repeater with a large array that you don't watch to watch every item.</strong></p> <p>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)</p> <p>something like (psuedo-code):</p> <pre><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('&lt;div&gt;' + d + '&lt;/div&gt;'); }); }); } }; }); </code></pre> <p>... which seems like a pain in the butt.</p> <p><strong>Alternate hackish method</strong></p> <p>You might be able to loop through <code>$scope.$$watchers</code> and examine <code>$scope.$$watchers[0].exp.exp</code> to see if it matches the expression you'd like to remove, then remove it with a simple <code>splice()</code> call. The PITA here, is that things like <code>Blah {{whatever}} Blah</code> between tags will be the expression, and will even include carriage returns.</p> <p>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 dunno.</p> <p>Either way, it seems like a hack.</p> <p><strong>To remove a watcher made by $scope.$watch</strong></p> <p>You can unregister a <code>$watch</code> with the function returned by the <code>$watch</code> call:</p> <p>For example, to have a <code>$watch</code> only fire once:</p> <pre><code>var unregister = $scope.$watch('whatever', function(){ alert('once!'); unregister(); }); </code></pre> <p>You can, of course call the unregister function any time you want... that was just an example.</p> <p><strong>Conclusion: There isn't really a great way to do exactly what you're asking</strong></p> <p>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.</p> <p>I hope that helps.</p> <hr> <p><strong>EDIT 2 (removed bad idea)</strong> </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload