Im getting undefined, undefined from ipCity and ipCountry
but i cant understand why.
weatherApp.service('cityService', function ($resource) {
var ipLocation = $resource("http://ipinfo.io", {callback: "JSON_CALLBACK"}, {get: {method: "JSONP"}});
var ipResult = ipLocation.get();
var ipCity = ipResult.city;
var ipCountry = ipResult.country;
console.log(ipResult);
this.city = ipCity + ", " + ipCountry;
})
LOG:
d {$promise: d, $resolved: false}
$promise: d
$resolved: true
city: "Toronto"
country: "CA"
hostname: "CPE00fc8d503cf3-CM00fc8d503cf0.cpe.net.cable.rogers.com"
ip: "99.232.37.198"
loc: "43.6555,-79.3626"
org: "AS812 Rogers Cable Communications Inc."
postal: "M5A"
region: "Ontario"
__proto__: d
So im basically getting the data from the API but i cant use the data into my service.
Resource.action([parameters], [success], [error])
". essentially,.get
is async, and won't immediately have a value.$resolved: false
first, then$resolved: true
on the second log.