1

Angular 2 recommends that template expressions be idempotent according to the following definition:

If the expression returns an object (including an Array), it returns the same object reference when called twice in a row.

What does angular care about the identity of that object? Put differently, what can happen if a template expression returns a new object with the same contents instead?

meriton
  • 68,356
  • 14
  • 108
  • 175
  • May be the function called only once by the parser? Avoiding loops and unnecessary processes? – Bruno João Dec 09 '16 at 19:51
  • I don't think it's related with angular; It's related with object immutability. More info: http://stackoverflow.com/questions/16115512/understanding-javascript-immutable-variable – eko Dec 09 '16 at 20:00
  • 1
    See also https://vsavkin.com/immutability-vs-encapsulation-90549ab74487#.6jn19d73g – silentsod Dec 09 '16 at 20:23
  • For Angular change detection to work Angular needs to know, what changed. It does a strict equality comparison and for objects its matching the reference. If you return a new object with same content, in production mode Angular change detection will not complain, but it development mode, Angular will log a warning in browser console. – Chandermani Dec 09 '16 at 20:59

0 Answers0