1

I have a Router <router-outlet></router-outlet> that includes the following route:

{ path: 'employee/:id', component: EmployeeComponent }

With an EmployeeComponent component already inside the router-outlet with a specific employee, I do the following in my code: this.router.navigateByUrl('/employee/'+this.employee2);

The url changes but the component does not execute the ngOnInit() method with the new Employee, and the content is not refreshed. I need to instantiate a new EmployeeComponent with an EmployeeComponent already on my router, or refresh the existing one. How can fix that?

1
  • IMO you should make use of ActivatedRoute Commented Mar 27, 2019 at 11:43

2 Answers 2

2

Need to inject "ActivatedRoute" and subscribe the params

constructor(route:ActivatedRoute){
      route.params.subscribe(val=>{ 
       //    add to do function()
      })
   }
Sign up to request clarification or add additional context in comments.

Comments

1

You can make use of AcitvatedRoute.

import { ActivatedRoute } from "@angular/router";

constructor(private route: ActivatedRoute) { }

Using Params

ngOnInit(){
  this.route.params.subscribe(param=>{
    console.log(+params['id'])
  })
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.