I'm facing an issue with a function that needs to return a value while containing a subscription. The problem I'm encountering is that the return line is being executed before the subscription ends,
testFunc(){
let objectType;
let moduleId;
objectType = valueAsString.split('|');
objectType = objectType[0];
this.layoutService.moduleIdByType(objectType)
.toPromise().then(data => {
moduleId = data;
});
return { IsById: true, LinkedModule: moduleId };
}
Within this code snippet, moduleIdbytype
is altering the value of the moduleId
variable. I need to ensure that I only return after the subscription has completed and modified the variable's value.