Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Inconsistent behaviour with track by and bindone when adding to list. #9508

Closed
KamBha opened this issue Oct 9, 2014 · 1 comment
Closed

Comments

@KamBha
Copy link

KamBha commented Oct 9, 2014

This is an Angular 1.3.0 issue. I was using firefox and tested on Chrome.

I was having a play with the bindone syntax and track by.

If you have a track by in a repeater and you bind once on a value, then you cannot change the value on the bound once value after the original binding (as you would expect). However, as soon as you add to the list then the change comes through. Plunkr provided to illustrate what I mean:-

http://plnkr.co/edit/u3Rbb40UKQYuTcK5pc94?p=preview

The "Modify Key" button modifies the key of the first item, the "Modify Value" button modifies the value of the first item. The "Add" button will add a value to the list.

If you do the following:-

  • Click on "Modify Key"
  • Click on "Modify Value"

Then, the bound once first value does not change. However, if you then click on add, then the bound once value is updated.

What I was hoping was to see is the bound once value would not be updated until the key changed - after which time the DOM would be re-rendered and the new value would be displayed. This would mean that we could use the track by mechanism as a means of significantly reducing the number of watchers. This was probably naive of me. Irrespective of how I feel it should work, I think it should work consistently - that is, it should either not change in all cases or change only when the key changes.

@Narretz
Copy link
Contributor

Narretz commented Nov 2, 2015

This works as expected. ngRepeat uses $watchCollection to check for changes in the collection. If you update only the key of an object, ngRepeat doesn't trigger the track by check etc at all. If you add an item, it will find that the key has changed, and rerender the changed item, which causes the change in the value to be picked up.

@Narretz Narretz closed this as completed Nov 2, 2015
Narretz added a commit that referenced this issue Nov 3, 2015
- mention $watchCollection
- highlight that track by "id" can improve render performance

Related #9508
Narretz added a commit that referenced this issue Nov 3, 2015
- mention $watchCollection
- highlight that track by "id" can improve render performance

Related #9508
gkalpak pushed a commit to gkalpak/angular.js that referenced this issue Nov 23, 2015
- mention $watchCollection
- highlight that track by "id" can improve render performance

Related angular#9508
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants