Angular JS – ngRepeat with TrackBy

With the TrackBy is possible to tell Angular how to recognize object within a collection to understand if, after an update, a particular index refers to the same updated object or to a new object. In this way Angular can avoid to destroy the DOM and re-create it each time, operating a more punctual update on element that are just changed in some field. This is better for performances and we don’t lose our markup bindings (e.g. the twitter post widget or the jQuery events) at each refresh.

<ul class="post-list">
    <li class="post {{ post.classNames }}" ng-repeat="post in blog.data.posts track by post.id">
        <post></post>
    </li>
</ul>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s