I have a function like this:
private data: MyCustomDataObject;
private getData(): boolean {
let val: boolean = true; // variable declared
this.service.callMethod().subscribe(data => {
this.data = data;
if (data == null) {
val = false; // val declared above is not updating
}
});
return val; // this is still true, should be false
}
How come val isn't updating?
val? (orgetData)?subscribeasynchronous? If so,getDatais returning before the function you pass tosubscribeever runsgetDatais called from another method in the same class, andvalis used in that same method that callsgetDatasubscribeis just a callback for when something changes. Am I right in guessing that?