Can someone provide guidance on how to set myVar to a value returned from an asynchronous service method in the following example?
angular.extend(this, {
myVar: (function() {
getVal();
})()
});
function getVal() {
var d = $q.defer();
MyFactory.Get()
.then(function (resp) {
d.resolve(resp.data);
});
return d.promise; // myVar should equal resp.data
};
I feel like I may be struggling with understanding promises/deferral, so any advice would be greatly appreciated.