I have a function that retrieves an array and assigns it to this.usStates
.
main(){
this.addressService.getState().subscribe( (data:any)=>{
this.usStates = data;
if(this.usStates.length===0) {
this.notificationService.showErrorNotification('Unable to get states');
console.log(this.usStates); //number of elements in the array is 10
}
});
console.log(this.usStates); //empty array displayed here
}
Is there a way to access the updated value of this.usStates
outside the callback's scope?