Is there any way to resolve (pre-fetch) data before rendering an component selector?
I would like to pre fetch data before rendering the root component.
You can use resolve in your router to prefetch data before going to loading a component with the router
path: myPath,
component: components.myComponent,
resolve: {
data: resolvers.service
}
https://blog.thoughtram.io/angular/2016/10/10/resolving-route-data-in-angular-2.html
I think you must implements ngOnInit of OnInit interface to resolve data before rendering. In the Lifecycle hooks of angular, NGOnInit: Initialize the directive/component after Angular first displays the data-bound properties and sets the directive/component's input properties. Called once, after the first ngOnChanges.