Trying to wrap my head around why this is not working. When I have my $http.get in my controller, I can convert the number stored in the JSON file to a array element like so:
$http.get('weapon.json').success(function(data) {
$scope.weapons = data;
for(i=0, len=$scope.weapons.length; i < len; i++){
$scope.weapons[i].ele = $scope.elementType[$scope.weapons[i].ele];
}
});
But when I try and move my $http.get into a factory, $scope.weapons[i].ele equal null instead of the array element.
.factory('WeaponData', function($http){
return $http.get('weapon.json');
})
.controller('BL2Ctrl', function($scope,WeaponData) {
WeaponData.success(function(data) {
$scope.weapons = data;
for(i=0, len=$scope.weapons.length; i < len; i++){
$scope.weapons[i].ele = $scope.elementType[$scope.weapons[i].ele];
}
});
})
here is a Plunker where it doesn't work