When navigating within a view, I use the following code:
this.router.navigateByUrl('/view1?result=' + action);
In view 1, I retrieve the value of the result parameter in the ngOnInit function:
ngOnInit(): void {
this.activatedRoute.queryParamMap.subscribe(queryParams => {
if (queryParams.get('result') != null) {
this.resultIdentity = queryParams.get('result');
}
});
}
Based on the value of "result", I trigger a click event on a button defined by ViewChild.
@ViewChild('alertButton') alertButton;
ngAfterViewInit(): void {
if (this.resultIdentity === 'XXX') {
this.alertButton.nativeElement.click();
}
}
If I directly visit the URL, the alert is displayed (even after refreshing the page). However, if I navigate using router.navigateByUrl, the modal doesn't show up properly – only the semi-transparent background appears without the modal itself.
Any insights into why this discrepancy occurs between navigation methods?
Thanks