0

I have seen two ways to lazy load components in angular :

  1. Using routes (using loadchildern)
  2. Using ViewContainerRef and ComponentFactoryResolver

What is the difference between both techniques?

1 Answer 1

4

As far as I know,

loadChildren is used to lazy load the modules but not the components. It means that you are loading all the components contained in the module into the browser. This will be helpful to lazy load feature modules

To lazy load components (feature of Angular 9), we need ComponentFactoryResolver.

ComponentFactoryResolver is also required to load any components dynamically (existing feature in all the Angular2+ versions)

Yes of course we need ViewContanierRef which acts as the placeholder to add new component at particular spot in the DOM

P.S: I am not adding example codes just to be within the limits of the question

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

1 Comment

thank you, i was actually confused between lazy loading components and modules. its clear now.

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.