I am having trouble retrieving the country name from a JSON file outside of its scope. I have tried using $rootScope but without much success. My goal is to use the country name as a variable in different scopes and on the page itself. Additionally, I need to send it to a database using Controller.cs (.net).
app.controller('PageController',
function ($scope, $http) {
var analyticsCountry = "default";
$.getJSON('//www.geoplugin.net/json.gp?jsoncallback=?',
function (data) {
$scope.testing = data;
$scope.testing.country = data.geoplugin_countryName;
//console.log($scope.testing.country);
analyticsCountry = $scope.testing.country;
});
console.log(analyticsCountry);
$scope.GetTrendingCDsByCountry = function () {
$http({
method: 'Get',
url: "/CD/GetTrending?id=" + analyticsCountry
})
.success(function (data, status, headers, config) {
$scope.cds= data;
})
.error(function (data, status, headers, config) {
$scope.message = 'Unexpected Error';
});
};
});