0

I am new to Angularjs and my app(built with Angular & Rails) is taking too much time to load the images/data. So I plan to optimize the code. Here is very quick and short question. What is the best way to use ng-repeat ? I planned to use track by in ng-repeat.

In my $scope.attributes I am getting thousands of data from server. In each there are many fields. But I wanted to use single field from those. SO I tried something like this:

<div ng-repeat="attribute in attributes track by attribute.name" >
<li> {{attribute.name}} </li>
</div>

Is this correct way? I have seen many examples everywhere use track by task.id So Can I use any specific field name instead of id ? Can I use filter also? what is the meaning of $$hashkey approach? I wanted to load images and it takes more time. Please want Experts advice.

Hetal Khunti
  • 787
  • 1
  • 9
  • 23

1 Answers1

1

if you track by .name it will use .name as the identifier, eg if the list changes it will find the ROW by .name

If the list will not change, look at one way binding

<div ng-repeat="attribute in ::attributes track by $index" >
<li> {{attribute.name}} </li>
</div>

-- I am sure that this will give you a DIV around the LI

Not related to your Q, but having just done some AngularJS performance tuning. Consider using ng-if instead of ng-show / ng-hide , ng-show/hide will still produce the DOM , ng-if will not. (You may have done this already)

Steve Drake
  • 1,968
  • 2
  • 19
  • 41