Working on a project where users can vote on items, and after an orderBy, the function works only on the original indexes of the items. I would like to track the items by their ID property which is pulled from the database but am having issues. I have also tried passing the objects rather than their indexes but again am having trouble getting my head around it.
Relevant JS
angular.module("cardSite", ['masonry'])
.controller('mainCtrl', function($scope, dataService) {
$scope.cards = [];
dataService.getCards().then(function(response) {
$scope.cards = response.data;
}, function() {});
$scope.plusOne = function($index) {
$scope.cards[$index].card_rating += 1;
};
});
Relevant HTML
<div class="col-lg-3 tile grid-item" ng-repeat="card in cards | orderBy : '-card_rating' | limitTo:8 track by card.ID">
<div class="panel panel-default {{ card.card_category | lowercase }}_panel">
<p>Card ID: {{card.ID}}</p>
<!DOCTYPE svg>
<p ng-click="plusOne($index)"> Vote up</p>
<p>{{card.card_rating}}</p>
</div>
Does anyone have any suggestions?