I want to know the current route of the application, when i checked i got solution where router.events.subscribe is used. But i saw conflicting solution like, some were coding in constructor and some were coding in ngOninit. Where exactly the code router.events.subscribe has to be placed.
Asked
Active
Viewed 181 times
1 Answers
0
I think the best way is to use ngOnInit()
Mostly we use ngOnInit for all the initialization/declaration and avoid stuff to work in the constructor. The constructor should only be used to initialize class members but shouldn't do actual "work".
So you should use constructor() to setup Dependency Injection and not much else. ngOnInit() is better place to "start" - it's where/when components' bindings are resolved.

Mohammad Babaei
- 473
- 6
- 16