How can I use a method with orderBy ?
I would like to sort my array from ng-repeat with a method and not a property :
index.html
<tbody>
<tr ng-repeat="product in results.data | orderBy: product.getAllCounter()">
<!-- Product name -->
<td ng-bind="(product.product_offer[0].app_name === null) ? product.app.store_id : product.product_offer[0].app_name"></td>
<!-- Counter -->
<td class="text-right" ng-bind="product.getAllCounter()"></td>
<!-- Action -->
<td class="text-center">
<div class="btn-group">
<a ng-href="/#/product/{{ product.id }}" type="button" class="btn btn-default btn-sm">
See
</a>
</div>
</td>
</tr>
</tbody>
Product.prototype.getAllCounter
// Return result all counter in promo
Product.prototype.getAllCounter = function () {
var sum = 0;
angular.forEach(this.product_promo_linker, function (product_promo_linker) {
sum += product_promo_linker.promo.count;
});
return sum;
};
I tried with
orderBy: product.getAllCounter()
and
orderBy: product.getAllCounter
The method product.getAllCounter return integer
SOLVED
I used :
<tr ng-repeat="campaign in results.data | orderBy: getAllCounter:true">
in my controller.js :
$scope.getCounter = function(product) {
return campaign.getAllCounter();
};