#Call ngOnInit from another unrelated component
3 messages · Page 1 of 1 (latest)
The solution is wrong in 3 ways: lifecycle hooks are meant to act upon lifecycle of a component. Here calling ngOnInit is not meant to affect navbar.
Secondly ngOnInit's block is just pure JavaScript. If you need to call what ngOnInit computes, move the logic to a dedicated function.
Finally the architecture is wrong. That's not a navbar responsibility to be the gatekeeper about the user's current status.
Such a logic should live in a service and both your navbar and your form components should use it directly.
how do I refresh the component tho?
if i don't call ngOnInit, then I can't refresh the component and make new change take effect?