I am trying to return a value from inside a foreach loop. I would like to explain it through the code.
Below code is a function where I am looping through the data which I am fetching from the database table via $http method of angular. After looping through I need to loop again because inventory is an array so, again I run foreach loop to get only the qty. I don't know if this is good practice or a bad one but I'm still getting my hands on angular. I have written this function to check if there is a negative quantity and if there is add a class of warning to the tr as written in the code down below. What I want to learn is returning the value from inside the foreach loop. When I try to log the qty inside of the loop it logs fine but outside of it does not. I have tried searching but could not find answers to it and that is why posting my question.
$scope.invPrice = function(){
for(var i in $scope.tableData)
{
$scope.pprice = $scope.tableData[i].inventory;
angular.forEach($scope.pprice, function(index) {
var qty = 0;
$scope.qty = index.qty;
qty = $scope.qty;
console.log(qty) //logs the qty
});
};
return qty;
};
<tr ng-class="{warning: invPrice() < 0}">