Search code examples
angularangular4-formsangular4-router

How to refresh a component on routing change when on the same component?


I am working on an angular 4 project and stuck in the following situation:

I have a two step booking form that is used for booking an appointment. I have two different industries lets say Industry A and Industry B, now when I am doing a booking lets say for industry A and go to step 2 and suppose I click other industry B(accessible by side menu) I am still stuck at step 2, I would like the page to be reloaded to step 1, so in short I want to access the same component with different routings.

In technical language, Am on a component and I want to refresh same component when routing is change. If anyone know about please let me know. Thanks in advance!


Solution

  • Try this may it solves your problem

    import { ActivatedRoute } from  '@angular/router';
    
    export class xyz {
       constructor (private activatedRoute: ActivatedRoute) {
    
       }
    
       ngOnInit() {
           // calls form when route parms change,
           // the method calls when your route params will change
           this.activatedRoute.params.subscribe (res => {
              this.validateForm();
           }    
       }
    
       // build form
       validateForm () {
    
       }
    }