Currently, I am facing an issue with my ng-repeat
block. In this block, I am generating elements based on data received from an ajax request, which sometimes causes a delay due to latency. Within the same block, I have implemented a filter to remove unwanted data by iterating through the list obtained from the ajax request. However, it seems like the list is not defined during this process.
After some consideration, I believe this problem may be attributed to the delay in the ajax request. Below is a snippet of my code:
HTML:
<div ng-repeat="item in items | doFilter: pricemin" >
<div><img src="images/nopreview.png" class="item-preview"/></div>
<div>{{item.NAME}}</div>
<div>{{item.PRICE}}{{item.CURRENCY}}</div>
<div>{{item.DESCRIPTION}}</div>
<div><button ng-click="addToCart(item)">Add To Cart</button></div>
</div>
Javascript:
app.filter('doFilter', function(){
return function(items, pricemin){
var minPrice = [], maxPrice = [];
for (var i =0; i < items.length; i++){
if (pricemin != "") {
if(pricemin <= items[i].PRICE)
minPrice.push(items[i]);
}
}
return minPrice;
};});
What would be the best approach to resolve this issue?