2

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.

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

That's not what I want. I know about resolve on routes, but I would like to resolve on a component which is not linked to a route, but a selector.
In that case ngOnInit like al37350 said it's what you want.
0

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.

1 Comment

It's not what I want but it will have to suffice. Rendering of page will not hold until completion of ngOnInit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.