I have this code written in AngularJS. I am not able to synchronize this. I want to resolve myData value before reaching if condition. But my code flow continues and It doesn't goes into 'IF' condition, because at that point myData is a promise function.
function() {
var dfd = $q.defer();
var myData = false;
var myData = restResource.get(itemId).queryOptions(options).promise().then(function(dataItem1) {
return restResource.oneAction(dataItem1.elements).then(function(dataItem2) {
var i;
if (dataItem2.items.length > 0) {
dfd.resolve(true);
return dfd.promise;
}
});
});
if(myData === true) {
dfd.resolve(item.attributes);
return dfd.promise;
}
//Another Resource call... code continues...
}
Also I tried to use $q.defer, but I think I am doing something wrong.
Let me know what is missing here.