Reputation: 29
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
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
Reputation: 1793
please try this:
ngOnChanges(changes: SimpleChanges) {
this.createComponent(this.wizardData);
}
Upvotes: 0