我在控制器中遇到问题,并且承诺。基本上我试图根据我对我的承诺productData
收到的回复创建if语句。问题在于承诺内存在变量productData
,但在它没有之后 - 变为空。是否因为范围?承诺范围变量
这里是我的代码:
var productData = null;
ProductService
.queryByGroup(selectedGroup.id)
.then(function(response) {
productData = response.data;
});
if (productData.hasOwnProperty('conditions') == false) {
// Send a request to the server asking for the medicine ids of the selected group
Meds
.getAllProductsById(selectedGroup.id)
.then(function(response) {
//SOME CODE logic
}, function(response) {
$log.debug('Unable to load data');
$log.debug(response.debug);
});
} else {
console.log("call modal");
}