I have a small app where i add city and country to the list and request weather for individual city using http request.
Whats the problem : When i have more than one cities in the list, and i request weather of perticular city, it updates weather for all the cities in the list;
What i want ? : I want to create a dynamic variable or array index where i can store and display weather info of individual city with its name as index. I am open to other solutions apart from dynamic variable or array index.
Is there a plnkr? : Here is the link to plunkr. Add 2 entries to reproduce the issue 1) pune, india 2) mumbai, india
What i tried : I tried to convert "destination" variable to string which is a function parameter to string using $parse and $scope.$eval() but that didnt worked.
Here is my getWeather function
$scope.getWeather = function(destination){
$http.get(destination+".json").then(
function successCallback (response){
if(response.data){
$scope.dest = {};
$scope.dest = response.data;
// $scope.info[$parse(destination)] = response.data;
// console.log($scope.info[$parse(destination)]);
}
},
function errorCallback (err){
alert(err);
}
);
}