How to update a component when changing a route when on a single component?

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

I have a two-story booking form that is used to book a meeting. I have two different industries: say, industry A and industry B, now that I am making a reservation, say, for industry A and go to step 2 and suppose I click on another industry B (available from the side menu). I still adhere to step 2, I would like the page to reload to step 1, so, in short, I want to access the same component with different routes.

In a technical language, Am is on a component, and I want to update the same component when changing routing. If anyone knows, please let me know. Thanks in advance!

+5
source share
2 answers

Try it, it may solve 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 () { } } 
+1
source

Hello, this is a design problem: just create a Map object with a status for each such company: formProgress [company] [step], then check the values ​​for changes in the route. Then in your HTML, create the form and all the steps as separate components so that you can use something like <div *ngIf="step===2"> on each HTML tag

To detect route changes, simply compare window.href.location or the previous route in a variable with activRoute parameters (at this point you need to learn more about routing)

0
source

Source: https://habr.com/ru/post/1274495/


All Articles