I have a list of json objects, $scope.phones, and a folder full of json files with additional data about each phone. I am trying to iterate through the files to grab additional information to put in my list about each phone:
phonecatControllers.controller('PhoneListCtrl', ['$scope', 'Phone',
function($scope, Phone) {
$scope.phones = Phone.query();
var myTimer = window.setTimeout(function() {
for (var i = 0; i < $scope.phones.length; i++){
var weight = 0;
Phone.get({phoneId: $scope.phones[i].id}, function( phone) {
weight = phone.sizeAndWeight.weight;
$scope.phones[i].weight = weight;
});
};
} , 1000 );
$scope.orderProp = 'age';
}]);
The timer is so that the function doesn't run until after scope.phones is set, (I realize its a bit of a hack but its not causing issues.) I get an error cannot set property of undefined on:
$scope.phones[i].weight = weight;
If i try to access this outside of the .get method there isn't a problem, however the new value of weight does not exist outside of the get method.