0

how can I lazy load component in angular 2? If I use the code below I get an error if I don't use both components on a html page.

Thank you, Matej

@NgModule({
    declarations: [AppComponent, SecondComponent],
    bootstrap: [AppComponent, SecondComponent]
})
Matej
  • 135
  • 1
  • 1
  • 7

1 Answers1

0

First : You can't bootstrap more than one components , it doesn't make sense. You'd only bootstrap one root component.

Second : If you wan't to load a component lazily/dynamically , you'd need to decide in which place that component should be created/loaded dynamically and then take it from there.

Third : A dynamic component should be in declaration of the module and in the entryComponents.

There are heaps of tutorials out there related to how to load a component dynamically , one would be

Angular2 RC6 - Dynamically load component from module

Community
  • 1
  • 1
Milad
  • 27,506
  • 11
  • 76
  • 85