Skip to content

Instantly share code, notes, and snippets.

@owrrpon
Created June 5, 2021 17:15
Show Gist options
  • Save owrrpon/dd30a3e9899ffbcb00db3f9f776d4fd2 to your computer and use it in GitHub Desktop.
Save owrrpon/dd30a3e9899ffbcb00db3f9f776d4fd2 to your computer and use it in GitHub Desktop.
Adding the logic to optimize the show/hide behavior based on the ongoing calls in app component.
ngAfterViewInit(){
let loader_control = this.global_utilities.getGlobalData('loading_animation_control');
this.loading_animation_control_sub = loader_control.subscribe(
(to_show: any) => {
// Show if the loader is not being shown already
if(to_show && !this.is_loader_showing){
this.is_loader_showing = true;
}
// Hide if the loader is being shown and there is no ongoing service call in next few seconds
if(!to_show && this.is_loader_showing){
let ongoing_call_check_interval = setInterval(
()=>{
let ongoing_call_count = this.global_utilities.getGlobalData('ongoing_request_count');
if(ongoing_call_count == 0){
this.is_loader_showing = false;
clearInterval(ongoing_call_check_interval);
}
}, 1000
);
}
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment