Angular Router navigate not firing ngOninit

283 Views Asked by At

I'm encountering an issue where the ngOnInit is not firing when returning to a page using the Angular router navigate.

//this fires and goes to the /test/parent-route
this.router.navigate(['/test/parent-route']

however the ngOnInit does not fire in the component of parent-route. The component loads, but ngOnInit does not trigger.

1

There are 1 best solutions below

0
Andrea Moretti On

Can you post more code? You wrote ngOninit instead of ngOnInit. To make sure you're calling the correct method add implements OnInit to your component (add OnInit in import from @angular/core)

import { OnInit} from '@angular/core';

...
export class MyComponent implements OnInit {
   ngOnInit() {
       // your code here
   }
}