I have the following data:
{
"fruits": [
{
"name": "apple",
"prices": [
{
"2015": 2,
"2014": 3,
"2013": 1
}
]
},
{
"name": "banana",
"prices": [
{
"2015": 4,
"2014": 1,
"2013": 3
}
]
}
]
}
In my .js file, inside my controller, I want to calculate the difference between the price of the latest year and the year before.
Such as:
Apples = 3 - 2 = -1
So that in my HTML I can do:
<div ng-repeat="fruit in fruits">
{{fruit.name}}, {{fruit.change}}
</div>
I've tried the following with no luck:
angular.forEach($scope.fruits, function(fruit, key) {
angular.forEach(fruit.prices, function(price, key) {
this.change = price[0] - price[1];
});
});