I'm trying to return each item object from a JSON and evaluate its value, with the angular.forEach()
, but only the last item is returned. And due to that I can't perform any evaluation. Funny enough, if I do console.log()
, it shows each item, one by one.
How can I get each item and evaluate them?
If you know of a better way, please teach me.
JS (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) {
// This is where I'm having problem with return data...
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';
}
});
});
}]);
HTML (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>
Many thanks