You have a wrong approach to the usecase you are trying to solve. Have a look at ngrx/store
and ngrx/effects
.
In short, you define actions and reducers which modify the state of your app. Next, you can react to different actions with different side-effects (ngrx/effects
), for example in my app I have got:
- Actions: LoginAction and LoginSuccessAction
- Effects: when LoginSuccessAction is triggered, my effect redirects to
/dashboard
component
This makes for nice separation of concerns:
- views display the current state and dispatch actions that change the state
- actions specify what happens in the app
- reducers specify what changes to state occur for different actions
- effects specify what side-effects occur for certain actions