Using angular-seed project: In directives.js
var names = [];
Animals.query(function(data){ // Animals.query() from service.js
console.log(data.Names); // output > [Object, Object..., Object]
names = data.Names; // attempt to bind to outer variable
});
console.log(names); // output > []
I can see the data there but I need it outside the function. How do I get it outside the function? console.log(names); happens before console.log(data.Names); I know it has to do with closures and maybe callbacks and I've tried many things and but I can't seem to get them to work for my case. I end up with an ever expanding mess of functions wrapped in callbacks wrapped in functions with still no binding to outside variable. I don't want to 'pollute the global namespace' but I need ahold of the data outside the inner function. The end-purpose is to get the data to be available for d3.js processing. There must be a simpler way. Can someone please help me with this particular case?