Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found a solution!</p> <p>After poking around and further checking the "track by" with my scenarios, I can see that it actually does more what it says:</p> <p>1) If you have a collection of objects, with each object having: id, name, description, you can, using 'track by' choose a property that it connects to, so, on retrieving a new collection of objects from a webservice, it will not render the DOM object belonging to the value.</p> <p>2) Most importantly, and what I was after: If an object with an existing id arrives from the server with fx a changed name, will it be reflected in the array collection on the object with that id? Yes, it will! So, "track by" will actually check the properties of the incoming object and replace the old object and still leave the id alone. That's intense.</p> <p>It's also worth noting that "track by" works also with other directives than <strong>ng-repeat</strong>, such as <strong>select</strong>.</p> <p>I made a small demo, for other people who might be confused about how everything works... but it seems to be cool!</p> <pre><code> &lt;div ng-repeat='country in countryArray track by country.id'&gt; {{country.id}} {{country.name}} &lt;input type="checkbox"&gt;&lt;/input&gt; &lt;/div&gt; &lt;div&gt; &lt;select ng-model='nonExisting' ng-options='country.name for country in countryArray track by country.id'&gt;&lt;/select&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p><a href="http://jsfiddle.net/KUf8C/">http://jsfiddle.net/KUf8C/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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