5

Does it matter to Angular if in every digest cycle I return a new list with the same contents vs returning the same list instance? This is assuming default change detection, not OnPush.

1 Answer 1

1

It will have some impact - ngFor will need to reevaluate each of the elements - it will do identity check. That should be quick, but if you have thousands elements in a big app it may add some overhead, so if you can it's better to return the same list each time.

1
  • Thanks. Can you elaborate more on what identity check is? Also, wouldn't it need to reevaluate each element regardless? If I understand correctly, ngFor will cause Angular to keep it's own copy of the list and has to do a deep comparison on every CD.
    – Dandan
    Apr 14, 2017 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.