I would like to set the ngxs state on application load. What would be the best way to do this?
e.g. resolve the state object in an angular APP_INITIALIZER and then ???
You could make the HTTP call to load data for the state via the ngxsOnInit
lifecycle hook see the lifecycle documentation here.
In my usage of NGXS we've typically had our states respond to a particular action e.g. UserLoggedIn
to load their initial data from an external service
We needed to wait on this action for two reasons:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With