I am facing an issue with a slow api call in my code.
$http.jsonp(url, {
params: {
'client': 'translate_about',
'alpha': 1,
'hl': 'en'
}
})
.success(function (data) {
home.translate.list = data.sl;
//console.log(data.sl);
});
The following code block needs to be executed either before or in parallel with the completion of home.translate.list
. Therefore, I require another block of code to update when home.translate.list
is successfully loaded.
home.modalOn = function (val) {
//open modal
home.isModal = true;
//this if block must wait for home.translate.list to be ready.
if(typeof home.translate.list !== 'undefined'){
home.activePageSelection = home.translate.list[val];
//call wikipedia and get data
home.callWiki(home.translate.list[val]);
}
};
$scope.$watch(function () {
return location.hash
}, function (value) {
var currentRouteParam = value.split('/').slice(-1)[0];
if (currentRouteParam !== '') {
home.modalOn(currentRouteParam);
} else {
home.modalOff()
}
});
Question:
Is there a way to ensure that home.translate.list
is defined before running the if block without including it in the $http.success
block?