distante distante - 24 days ago 7
AngularJS Question

How to add correctly "track by" to ngRepeat

I have this html

<ion-item ng-repeat="item in ::itemsToShow = extensionItems | orderBy:'distance' " class="entry" ng-class="{'alt-background': $index % 2 == 1}" ng-click="itemDetail(item)">
...details...
</ion-item>


I can't figure out the correct way to add
track by:item._id
I always get this error:


Syntax Error: Token 'track' is an unexpected token at column 30 of the expression [itemsToShow = extensionItems track by:_id |...


I tried:

<ion-item ng-repeat="item in ::itemsToShow = extensionItems track by:item._id | orderBy:'distance' " class="entry" ng-class="{'alt-background': $index % 2 == 1}" ng-click="itemDetail(item)">

<ion-item ng-repeat="item in ::itemsToShow = extensionItems track by:_id | orderBy:'distance' " class="entry" ng-class="{'alt-background': $index % 2 == 1}" ng-click="itemDetail(item)">

<ion-item ng-repeat="item in ::itemsToShow = extensionItems | orderBy:'distance' track by:_id" class="entry" ng-class="{'alt-background': $index % 2 == 1}" ng-click="itemDetail(item)">

<ion-item ng-repeat="item in ::itemsToShow track by:_id = extensionItems | orderBy:'distance' " class="entry" ng-class="{'alt-background': $index % 2 == 1}" ng-click="itemDetail(item)">


Also tried using
_id
and
item._id
and I always get the same error (different column of course). How or where should I write the
track by
?

Edit: Angular version 1.4.3

Edit 2: The Json data have this structure

_id: "000000426"
_rev: "1-5003008fcf25b8f130233b944bb761c9"
someText: "<p class="bodytext ">Something for you.</p>"
name : "You-Shop"
homepage : "http://www.youshop.com"
id: 426

Answer

You just miss the fact track by must not be followed by a colon (:)...