'Reload component after back from redirection in angular 8
I make a external redirection with window.location.href to another page, but as external page take too much time to load, i show a spinner in my page (managed with loadingRedirection flag). But when i go back to my page, flag still true. I put to false in ngOnInit, but angular doesnt detect changes. i tried also call ChangeDetectorRef.detectChanges(), but still not working This is my component
@Component({
selector: 'app-landing',
templateUrl: './landing.component.html',
})
export class LandingComponent implements OnInit {
loadingRedirection = false;
constructor() {}
goToGoogle() {
this.loadingRedirection = true;
window.location.href = 'https://google.es';
}
ngOnInit(): void {
this.loadingRedirection = false;
console.log(this.loadingRedirection); // show false
}
}
And my simplified html page
<a (click)="goToGoogle()">Go to Google</a>
{{loadingRedirection}} <!-- Shows true after load after go back -->
<app-loader *ngIf="loadingRedirection"></app-loader>
<main *ngIf="!loadingRedirection">
My code...
</main>
I also tried to use ngOnDestroy, but its not a solution since its called when i click the link
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|