This is a function in Javascript that I need for checking an Angular service by subscribe if it contains an array or not but the the return value is undefined because the function doesn't change the variable value inside the subscribe.
function checkAvailableBonus() {
var dataSize = 0;
var returnValue = "false";
window.angularComponentRef.component.slotsBonusesService.getPlayerAvailableBonuses().subscribe(function (data) {
dataSize = data.length;
if (dataSize !== 0) {
returnValue = "true";
} else {
returnValue = "false";
}
});
return (returnValue);
}
checkAvailableBonus();
I except the function to return "true"/"false" after the subscribe was done.