Struggling to loop through each item object in a JSON data set and evaluate its value using angular.forEach()
. However, only the last item is being returned, making it impossible to perform any meaningful evaluation. Oddly enough, when using console.log()
, each item is shown individually.
Any suggestions on how to properly retrieve and evaluate each item?
If you have a more efficient solution, I would appreciate the guidance.
Here's the JavaScript code (AngularJS):
angular.module('bLiApp')
.controller('AddDataCtrl', ['$scope', 'DataService', function ($scope, DataService) {
DataService.getItems().success(function(data) {
$scope.items = data.category.items;
angular.forEach($scope.items, function(item) {
// Struggling with returning data here...
if (item.amount < 600) {
$scope.amountchecker = 'low';
} else if (item.amount >= 600 && item.amount <= 650) {
$scope.amountchecker = 'average';
} else if (item.amount > 650) {
$scope.amountchecker = 'too high';
}
});
});
}]);
And here is the HTML code (AngularJS):
<div class="add-data" ng-controller="AddDataCtrl">
<div class="data-box clearfix" ng-repeat="item in items">
<article class="item">
<p>{{amountchecker}}</p>
<p><span class="month">{{ item.month.substring(0, 3) }}</span></p>
<p class="cost">{{item.cost | currency:"£"}}</p>
</article>
</div>
</div>
Your assistance is greatly appreciated.