-2

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.

RDK
  • 69
  • 4
  • I'm not familiar with adding a path to the route. what's the purpose of that? – Rick Mar 15 '23 at 18:02
  • Apart from the typo's that have been pointed out, you are not giving enough information. Are you trying to route back by any chance? If the component you are routing to is a parent with its own outlet, that component has not been destroyed and it's `ngOnInit` will not be called again. – H3AR7B3A7 Mar 15 '23 at 18:34
  • Yes I'm trying to route back – RDK Mar 15 '23 at 20:04

1 Answers1

2

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
   }
}