I am trying to get json data from an external json file, I want to get data every second and the use it in other functions but when I console.log myData outside of the function it returns an empty object while when I console.log(myData) from outside it returns the data. How can I take this out of the function
var myData = {};
function getData(){
var deferred = $q.defer();
var path = 'http://orbit5.ds.cs.umu.se:8888/vrio/debug/blk'
$http.get(path)
.success(function(data){
if(data) {
myData = data
deferred.resolve(data);
console.log(myData)
} else {
console.log('cant process')
}
})
return deferred.promise;
}
$timeout(getData, 1000)
console.log(myData)
My question is regarding angular code I do not understand the answer I am directed to if someone can point me to a simpler explanation that would be nice