What is the best way to reload or refresh ngAfterViewInit when the query parameters value changes within the same component?

When the ngAfterViewInit() event is triggered, I am using the createComponent(this.queryparams) method to pass the query parameters value and dynamically load a component based on those parameters.

However, I have noticed that the component only loads once during the initial page load. Subsequent changes in the query parameter values do not trigger a reload of the component.

Is there a way to refresh or reload the ngAfterViewInit() event when the query parameter values change?

Answer №1

To dynamically update data based on route parameters, you can subscribe to the ActivatedRoute params and reload the method using those params whenever they change. Here's how you can implement it:

component.html:

***
constructor(){
 this.activatedRoute.params.subscribe(params => {
        this.id = params.id;
        this.name = params.name;
        this.ngAfterViewInit(); // or any other method where you utilize these query parameters
    });
***

I hope this solution proves useful for you!

Answer №2

Give this a shot:

In the ngOnChanges method, pass in the changes parameter of SimpleChanges type and call the createComponent function with this.wizardData as an argument.

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

Can the type of an object be dynamically assigned in Typescript?

I keep encountering the eslint warning "@typescript-eslint/no-unsafe-assignment". This warning occurs when I am trying to extract specific keys and values from a variable that can be assigned objects of different types, with approximately 10 possible class ...

Combining Angular 2 and Symfony 3 for seamless integration

I am currently working on integrating Angular 2 with Symfony 3. After using npm to install node modules, I encountered an issue linking them from my base view base.html.twig. Despite adding scripts, none of them seem to be working or appearing in the page& ...

Combining several objects into a single one in TypeScript while handling duplicate keys

I'm currently using ng2-charts and I'm looking to create a horizontal bar chart. The values are obtained within a keys.forEach loop, resulting in the console.log output for my data as follows: {ReasonA: 5} {ReasonA: 5, ReasonB: 5} {ReasonA: 1, R ...

I encountered an issue in my Angular application where I continually receive the error message stating "Module 'fs' cannot be found."

Within my service file, I have imported four crucial libraries: import * as async from "async"; import * as officegen from "officegen"; import * as path from "path"; import * as fs from "fs"; All seems to be functioning well with async, officegen, and pa ...

What is the reason behind Ramda having multiple curry functions in its source code, much like Redux having multiple compose functions?

There are _curry1, _curry2, _curry3, and _curryN functions within the depths of Ramda's source code This interesting pattern is also utilized in the redux compose function I find myself pondering: why did they choose this intricate pattern over a mo ...

Displaying Information in Angular Modal Windows

I'm facing an issue while trying to create an edit button for a formGroup that is initially saved. When the user clicks on the adjacent button, a modal should open with editable data. However, I encountered this error and haven't been able to res ...

The type 'AxiosResponse<IUser, any>' is not to be mistaken for an array type

I am facing a minor issue while working with axios response in my code. I have a method that fetches user profiles from an API: static async getProfileById(id: string | undefined){ const jwt = localStorage.getItem("jwt"); const response ...

When attempting to apply generic Specification and Visitor patterns, the type does not meet the constraint and improperly extends the interface

I am currently working on incorporating a generic Specification pattern and a generic Visitor pattern simultaneously. Below are the base interfaces I have developed for this implementation. export interface Specification<T, TVisitor extends Specificatio ...

Tips for utilizing multiple ngFor directives for property binding within a single directive

After implementing the ng-drag and drop npm module with the draggable directive, I encountered an issue while trying to display a list of items from a 2D array using li elements. Since multiple ngFor's are not allowed in Angular, I needed to come up w ...

Experimenting with directive using jasmine

I've been working on this directive but I'm having trouble writing the jasmine test for it. Any suggestions? import { Directive, Output, EventEmitter, HostListener } from '@angular/core'; @Directive({ selector: '[ctrlKeys]&apos ...

Is Angular Universal better suited for AWS Lambda or EC2?

Looking for feedback on hosting an Angular Universal app. Debating between EC2 and AWS Lambda - thoughts? Initially set up a t2.micro Linux instance to host my app and was pleased with a 97 score on Google's page speed insights test. However, came ...

What is the best way to create a props interface that includes state and setState values that are being

As I dive deeper into TypeScript, a hurdle has appeared in my app. Upon introducing React.FunctionComponent to my components, an issue arose with my Props interface. The error message reads: Type '({ value, setValue, }: Props) => JSX.Element' ...

Avoid redundant GET requests in your Angular application initialization by utilizing RxJS

Is there a way to consolidate multiple http requests into one in Angular or RxJS, if they are triggered closely together? For instance, when I open my application, all 20 components call the same http request in their ngOnInit method: https://i.sstatic.n ...

typeorm migration:generate - Oops! Could not access the file

When attempting to create a Type ORM migration file using the typeorm migration:generate InitialSetup -d ormconfig.ts command, I encountered an error: Error: Unable to open file: "C:\_work\template-db\ormconfig.ts". Cannot use impo ...

Is it possible to create a typeguard for a complex combinatory type while retaining the existing type information?

Is there a method to create a TypeScript typeguard for a complex combinatory type that includes multiple "and" and "or" statements to check for the presence of one of the "or" types? For example: interface Type1 { cat: string } interface Type2 { d ...

Guidelines for assigning dynamic values from an array to a button in Angular2

I am a beginner in Angular and I am looking to display dynamic data with edit and delete buttons. I have managed to display the data properly with headers and everything, but now I want to add an edit button. Currently, I am passing each record's ID ...

Oops! There seems to be an issue: Uncaught promise error - ReferenceError: google is not defined

I've integrated Angular 2 with Google Maps Places Autocomplete in my project, but I encountered an error: ERROR Error: Uncaught (in promise): ReferenceError: google is not defined Here's the HTML snippet: <agm-map id="googleMap"> ...

I am unable to retrieve data from a promise object in the drop-down; however, I can see the data in the console response. This issue is occurring in

Here is the code snippet from the component.ts file: deptList: Department[]; ngOnInit() { this.service.getDeptList().then(res => this.deptList = res as Department[]); this.resetForm(); } The service.ts code snippet is shown below: getDe ...

Angular component as well as its corresponding helper service or utility class

I recently started using Angular 5 and I'm working on creating a component with a lot of logic to prepare data for display in HTML. From what I understand, it's recommended to move this logic out of the component to avoid triggering change track ...

We are currently unable to identify the specific web framework being used. For further details, please refer to the firebase-debug

I encountered an issue during the deployment process of my Angular application to Firebase Hosting using the firebase deploy command. The error message I received is as follows: [2024-01-31T22:26:15.400Z] --------------------------------------------------- ...