Abhishek Kumar
Abhishek Kumar

Reputation: 29

How to load/refresh ngAfterViewInit after query params value changes on same component?

I am loading createComponent(this.queryparams) method ngAfterViewInit() event and passing the queryparams value in createComponent method. Depending upon the query params value I am loading Component dynamically.

But the component is loading once only on page load and when query param value is changing it is not loading the component.

How to refresh/load the ngAfterViewInit() on query param value changes?

Upvotes: 1

Views: 2185

Answers (2)

Milos Kovacevic
Milos Kovacevic

Reputation: 891

You could subscribe to actvatedRoute params, and when params change, just simply reload the method where you use those params. Let‘s see that in action:

component.html:

***
constructor(){
 this.activatedRoute.params.subscribe(params => {
        this.id = params.id;
        this.name = params.name;
        this.ngAfterViewInit(); // or some other method where you are using those query parameters
    });
***

Hope this will help you!

Upvotes: 1

Seba Cherian
Seba Cherian

Reputation: 1793

please try this:

ngOnChanges(changes: SimpleChanges) {
       this.createComponent(this.wizardData);
   }

Upvotes: 0

Related Questions