8

Is there a way in angular to lazy load component directly from the tag in html like <my-component></my-component>?

during component template parsing, angular should load the entire component into the browser when it finds any new tag which is not available in html or not already loaded.

I know we can load a module using loadChildren which is only specific to routing and also need to load the module and its component. I am searching only for component and directly the component not the module.

I dont want to use router or dont want to import the component ot module in my application. I want when angular2 will find a tag which is not in html5 it will search in a spcictfic folder and load the js and html file and inject that component in the specific tag

6
  • Have a look here: stackoverflow.com/questions/38888008/… Commented Nov 20, 2016 at 16:46
  • 2
    stackoverflow.com/questions/40293240/… Commented Nov 22, 2016 at 9:09
  • @yurzui The duplicate marked link is about lazy loading of module not component. I have asked how to lazy load the component without thinking about the module or anything else. Commented Jun 13, 2017 at 19:31
  • Angular doesn't support lazy loading component without module. In any case you have to create module even that will consist of only one component Commented Jun 13, 2017 at 19:34
  • @yurzui so the question is not duplicate right? Commented Jun 13, 2017 at 19:42

1 Answer 1

0

In your case you have to use dynamic component loading with component builder, which has limitation with AOT, Dynamic component will not work with AOT.

Dynamic component loading will find your tag and load appropriate component in DOM

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

10 Comments

Dynamic component can work with AOT
Can I have article Or link where I can look. I really required to implement in my project
stackoverflow.com/questions/40060498/… For AOT compilation see these threads
@yurzui: Thanks for link, I will check and let you know if any help is required.
In above example you runtime add RunTimeCompiledComponent in RuntimeComponentModule with entry point define. What if i have multiple component and among that i have to add any one in "RuntimeComponentModule"? not the default one (RunTimeCompiledComponent). In my page no any predefined that this component will load dynamic, it's by configuration so any comonent can load dynamically
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.