I'm trying to learn Angular and have written the following code to find my IP. I can easily access and print the IP to the console inside SUCCESS but fail to access it outside of the GET method. Even setting the variable to response inside SUCCESS doesn't do job. Any help would be highly appreciated.
var app = angular.module('myApp', []);
var ip;
app.controller('customersCtrl', function($scope, $http) {
console.log("Console Works");
$http.get("https://api.ipify.org/")
.success(function (response) {
console.log("Success " + response);
ip = response;
console.log("IP Inside: " + ip);
});
});
console.log("IP Outside: " + ip);
Console prints:
IP Outside: undefined
Console Works
Success 11.222.222.11
IP Inside: 11.222.222.11