I want a service that grabs info from an API but only after clicking an HTML element.
"freegeoip.net/json/" + ip_address
The problem is, my service and URL above is being called before the click occurs.
app.service("ips", function ($http, $q)
{
// Grab json
var deferred = $q.defer();
$http.get("http://www.freegeoip.net/json/" + ip_address).then(function (data)
{
deferred.resolve(data);
});
this.getItems = function ()
{
console.log(deferred.promise);
return deferred.promise;
}
})
Can someone show me I can define this variable ip_address later in a click?
///Inside the controller
promise.then(function (data)
{
$scope.items = data.data.items;
});
$scope.defineIP= function(item)
{
ip_address = "212.38.168.60"
return ip_address;
}
The problem here is that I have no clue how to take this value i defined for ip_address and inject it into the service.