There is no modal displayed in Angular when I navigate to a different page

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

Answer №1

Providing a practical demonstration would be extremely helpful in addressing your question thoroughly.

Seemingly, the issue appears to stem from the asynchronous behavior of ngOnInit, ngAfterviewInit, and ...queryParamsMap.subscribe().

It can't be guaranteed that these functions will always execute in the same sequence.

To troubleshoot, I recommend inserting console.log statements within each function to observe any discrepancies in order between your two scenarios.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering a 400 error code while attempting to upload an image file on Imgur

Having trouble uploading an image file from my React app. I keep receiving a 400 error, which is puzzling me. Here's the TypeScript function code from my React application: public setImage = (args: ChangeEvent<HTMLInputElement>) => { ...

Instructions for setting up a session where the user can input data at a later time

Is there a method to save user input so that they can return to continue filling out a form from where they left off? I am in need of assistance as I am unsure of the optimal way to achieve this. Thank you in advance for any help. ...

Dynamic Material UI Timeline

I am facing a challenge with making the Timeline in Material UI responsive for the first time. Currently, I have it set to align 'alternate', but I want it to switch to align 'left' when viewed on mobile or certain screen widths. I have ...

Strategies for preventing profanity in Typescript within Nuxt 2 implementation

implement user authorization functionality create the Auth class for authentication handling import type { Context } from '@nuxt/types'; export class Auth { public ctx: Context; constructor(ctx: Context) { t ...

The concept of Nested TypeScript Map Value Type

Similar to Nested Typescript Map Type, this case involves nesting on the "value" side. Typescript Playground const mapObjectObject: Map<string, string | Map<string, string>> = new Map(Object.entries({ "a": "b", &quo ...

Encountering a problem with fetching data in a dropdown using a hidden select in MVC 4 Razor and Selectpicker

I need to show my hidden select data in dropdown-menu inner selectpicker ul with the default "--choose--" option selected. ASP.NET MVC Razor Syntax @Html.DropDownListFor(model => model.BrandName, Model.CompanyItems, "--Choose Brand--", new { @id = "B ...

Exploring the DynamoDB List Data Type

Currently, I am working on an angular 8 application where I have chosen to store JSON data in a list data type within DynamoDB. Inserting records and querying the table for data has been smooth sailing so far. However, I have run into some challenges when ...

The Typescript errors is reporting an issue with implementing the interface because the type 'Subject<boolean>' is not compatible with 'Subject<boolean>'

Creating an Angular 2 and Typescript application. I am facing an issue with an abstract class within an NPM package that I am trying to implement in my app code. Everything was functioning correctly until I introduced the public isLoggedIn:Subject<bool ...

When using Webpack and Typescript together with the watch feature, an error with code TS2554 may occur only during

Software in use: webpack 4.8.3 typescript 2.8.3 ts-loader 4.3.0 Configuration for Webpack: rules: [ { test: /\.ts(x?)$/, exclude: /node_modules/, use: ['ng-annotate-loader', 'ts-loader'] }, . ...

The identification token, access token, and user information tokens are essential components for

I am utilizing Angular for the front-end and Spring Boot for the back-end. The back-end needs to have knowledge of the authenticated user. It appears that there is an id token and access token. User role access will be managed by the Spring Boot applicat ...

Using Typescript for AngularJS bindings with ng.IComponentController

Currently, I am utilizing webpack alongside Babel and Typescript Presently, the controller in question is as follows: // HelloWorldController.ts class HelloWorldController implements ng.IComponentController { constructor(private $scope: ng.IScope) { } ...

Tips on concealing the scrollbar only when a particular element is visible

I inserted the following code into my index.html file: <head> <style> body::-webkit-scrollbar { display: none; } </style> </head> This code successfully hides the scrollbar. My goal is to only h ...

The presence of a default value within an Angular ControlValueAccessor triggers the dirty state due to

My task is to create dynamic Input components for a template driven form using a directive. The default value of the Input component should be set by the component itself. However, I encountered an issue where setting a default value automatically marks t ...

Is there a way to bring in data from a .d.ts file into a .js file that shares its name?

I am in the process of writing JavaScript code and I want to ensure type safety using TypeScript with JSDoc. Since it's more convenient to define types in TypeScript, my intention was to place the type definitions in a .d.ts file alongside my .js fil ...

The double deletion of all input causes a glitch in the two-way binding functionality

I attempted to prevent an input from being empty, but found that when using the method of selecting all text and then pressing backspace, the input only updates every other attempt. To see this issue in action visit: https://stackblitz.com/edit/angular-em ...

Unable to import Express in Angular

In my Angular app, there are no syntax errors present. Within a file titled test1.js, I have only one line of code: var express = require('express'); However, I am encountering an error in my log: (Interestingly, commenting out this single l ...

Creating a number of arrays based on the row of a .CSV file can be accomplished in Angular by utilizing the

Implementing an Angular template to read .CSV files and generate a table involves creating two separate files: one for the header and another for the table content. For the header CSV file: header.csv https://i.stack.imgur.com/ojMo6.png For the table da ...

The intersection of conditional types and the combination of string literals with class unions

Encountered an unusual behavior in the types system when trying to type the as prop from emotion. import React, { Component, FC, PropsWithChildren } from "react"; // Defining possible types for `as` prop type AsType = | keyof JSX.IntrinsicElements | ...

Any alterations made to an object in one component result in changes being reflected across all components

I currently have the following item.ts file: item.ts export interface IItem { name: string; isActive?: boolean; } const data: IItem[] = [ { name: 'item1', isActive: true }, { name: 'item2', isActive: true } ...

Utilizing Reactjs and typescript to dynamically set width and height properties of a div element using randomly generated variables

I am attempting to set a randomly generated variable as the width and height of a div. I have successfully written a function that generates a random size, but encounter an error when trying to assign it to the style attribute. My objective is to create a ...