TransWikia.com

How does AngularJS manage scope in ng-repeats?

Software Engineering Asked by Scottie on January 31, 2021

I have a table that has around 60 rows and 20 columns. Each cell has a directive with an isolated scope. I use 2 nested ng-repeats to generate the table (one for rows and one for columns), but I’m wondering how angular handles scope when a digest cycle causes a re-generation of the directives in the ng-repeats?

Does it destroy all the previous isolated scopes in my directives and create new ones, or are those old isolated scopes now orphaned somewhere and memory leaking as more and more digests take place?

Is this something that I, as a developer, should be aware of and make sure to handle the destruction of any isolated scopes?

One Answer

Use the changelog and the test specs for a high-level understanding of ng-repeat and how it changed between Angular versions:

  • select: keep ngModel when selected option is recreated by ngRepeat
  • ngRepeat: add support to iterate an object's properties even if it does not inherit from Object
  • ngRepeat: do not sort object keys alphabetically
  • ngRepeat: allow extra whitespaces in (key,value) part of micro-syntax
  • ngRepeat: support cyclic object references in error messages
  • ngRepeat: preserve original position of elements that are being animated away
  • ngRepeat: improve errors for duplicate items
  • allow aliasAs identifiers which contain but do not match reserved words
  • make allowed aliasAs expressions more strict
  • simplify code and remove duplicate array.length access
  • optimize marking of nodes that are being removed via an animation
  • use no-proto objects for blockMaps
  • move work to compile fn
  • move updateScope fn to factory and reuse it for all repeaters
  • clone boundary comment nodes
  • ngRepeat: provide support for aliasing filtered repeater results as a scope member
  • ngRepeat: ensure that the correct (transcluded) scope is used
  • ngRepeat: allow for more flexible coding style in ngRepeat expression
  • ngRepeat: allow multiline expressions
  • ngRepeat: support repeating over ngInclude and other directives that replace repeated nodes
  • ngRepeat: correctly track elements even when the collection is initially undefined
  • ngRepeat: add $even and $odd props to iterator
  • handle iteration over identical obj values
  • support growing over multi-element groups
  • correctly iterate over array-like objects
  • prevent initial duplicates
  • ngRepeat: add support for custom tracking of items
  • ngRepeat: due to 61f2767c, it is now considered an error to have two identical items (identified by the new "track by" expression) in a collection that is fed into the repeater. This behavior was previously tolerated.
  • ngRepeat: correctly apply $last if repeating over object
  • ngRepeat: now works better with primitive types
  • ngRepeat: expose $first, $middle and $last instead of $position

Answered by Paul Sweatte on January 31, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP