title: Angular 6 display components of a lazy loaded module
body: <p>I am having issues with loading a component from a lazy loaded module, using Angular 6.</p>
  
  <p>I created a library using the CLI - 
  <code>ng generate library @org/chat</code></p>
  
  <p>Updated <code>angular.json</code> file to include:</p>
  
  <pre><code>"lazyModules": [
     "dist/org/chat"
  ],
  </code></pre>
  
  <p>and then loading the module successfully via AppComponent:</p>
  
  <pre><code>constructor(private _injector: Injector, private loader: SystemJsNgModuleLoader, public dialog: MatDialog) {}
  
  load() {
     this.loader.load('dist/org/chat#ChatModule').then(moduleFactory =&gt; {
      const moduleRef = moduleFactory.create(this._injector);
     });
  }
  </code></pre>
  
  <p>So far so good and the module is being loaded.</p>
  
  <p>However, the ChatModule has a component called ChatPopupComponent and I can't find a way to show it using a dialog (or by adding it to a ViewChild container).</p>
  
  <p>In order to open a component in a dialog it needs to be declared under the module's entryComponents plus imported at the AppComponent level:</p>
  
  <pre><code> let dialogRef = this.dialog.open(ChatPopupComponent
       data: {}
    });
  </code></pre>
  
  <p>But when importing the component directly (and exporting it from the library) I get the following (obvious) error: '<code>Component ChatPopupComponent is not part of any NgModule or the module has not been imported into your module</code>'. Since it is a lazy loaded module, it is clearly not imported yet.</p>
  
  <p>When I try the following:</p>
  
  <pre><code>   let name: any = 'ChatPopupComponent';
     let dialogRef = this.dialog.open(name
           data: {}
        });
  </code></pre>
  
  <p>I get the following error - <code>error loading module Error: No component factory found for EmailPopUpComponent. Did you add it to @NgModule.entryComponents?</code></p>
  
  <p>It seems that the only way to show a component is by importing the module within the <code>app.module.ts</code>, although it defies the goal of having a lazy loaded module.</p>
  
  <p>Is there a way to do the above or am I missing something rudimental about lazy loading modules &amp; components?</p>