Why would one return an Observable from a resolver in Angular? How is this different than simply subscribing to a method in a service/store in the component itself? I thought a resolver's purpose is to ensure the data is present before the component loads.
From Angular.IO's documentation about Resolve
:
Resolve
Interface that classes can implement to be a data provider. A data provider class can be used with the router to resolve data during navigation. The interface defines a
resolve()
method that will be invoked when the navigation starts. The router will then wait for the data to be resolved before the route is finally activated.
It's different than simply subscribe
ing to a method in a service/store in the component itself because in that case, the route that loads up the Component would already be activated and the API call would be made after that. So the user would probably have to wait for the data to load up.
Now, in most of the cases you'd not require Resolve
in the first place. It's only a matter of how fast your API responds and whether there's a significant delay in fetching the data that might hamper the UX.