I can't wrap my head around AngularJS' concept of promises.
I have a provider:
var packingProvider = angular.module('packingProvider',[]);
packingProvider.provider('packingProvider',function(){
return{
$get: function($http){
return{
getPackings: function(){
$http.post('../sys/core/fetchPacking.php').then(function(promise){
var packings = promise.data;
return packings;
});
}
}
}
}
});
As you can see, this provides a method getPackings()
, which will return an object
Now, if I use that in my main application to receive the data, the call will be asynchronous, resulting in an issue where I would have to 'wait' for the data:
var packings = packingProvider.getPackings();
console.log(packings); // undefined
How would i do this without refactoring the process into my main controller?