title: Why Angular requires us to declare dynamic components in declarations array and entryComponents array?
body: <p>I was implementing dynamic components for one of my project. The concept of dynamic components is that they come into the memory once they are needed and they have no reference in any template.</p>
  
  <p>According to the official <a href="https://angular.io/guide/entry-components" rel="noreferrer">docs</a> we declare such components in <code>entryComponents</code> to prevent them from getting discarded in the <strong>tree shaking</strong> process as they have no template reference.</p>
  
  <p>Following is the <code>app.module.ts</code> where I have declared my two dynamic components <code>SlideOneComponent</code> and <code>SlideTwoComponent</code> in the <code>entryComponents</code> array:</p>
  
  <pre><code>  @NgModule({
    declarations: [
      AppComponent,
      ButtonComponent,
      AdDirective
    ],
    imports: [
      BrowserModule
    ],
    providers: [],
    entryComponents: [
        SlideOneComponent,
        SlideTwoComponent,
    ],
    bootstrap: [AppComponent]
  })
  export class AppModule { }
  </code></pre>
  
  <p>With above <code>app.module.ts</code> I am getting following error: </p>
  
  <p><a href="https://i.stack.imgur.com/YMDM0.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/YMDM0.jpg" alt="enter image description here"></a></p>
  
  <p>The above error fades away as soon as I add my both dynamic components to <code>declarations</code> array. The aforementioned official docs also says that we do not need to declare components that are reachable from <code>entryComponents</code> or <code>bootstrap</code> component. I visited <a href="https://stackoverflow.com/questions/40819777/placing-components-in-declarations-array-as-well-as-entrycomponents-array">this</a> answer as well but that does not seem to be satisfactory enough as it is in reference to Ionic.</p>
  
  <p>Please help me to know where I am missing on this. Thanks in advance! :)</p>