4

In my Angular2 module I've specified an array of components in the entryComponents property like this:

  @NgModule({
   // ...
    entryComponents: [ComponentA, ComponentB]
   // ...
  })
  export class AppModule { }

In a component I want to access this list of entryComponents. Something like this:

import { Component } from '@angular/core';


@Component({
  selector: 'my-selector',
  // ...
})
export class MyComponent{

  // Something like this:
  constructor(private moduleRef: ModuleRef){
    console.log(moduleRef.entryComponents);
  }
}

Is this possible in any way? I do not need an explicit reference to the module itself but only on the entryComponents list.

Thanks for your help!

Zteve
  • 341
  • 1
  • 2
  • 12
  • They may be not reachable at all because there's no idiomatic reason to do this. Why would you need that? – Estus Flask Nov 07 '16 at 14:27
  • 1
    I followed this solution for dynamic module creation: http://stackoverflow.com/questions/36325212/angular-2-dynamic-tabs-with-user-click-chosen-components But in my case: My "type" array contains only strings, as it comes from external data. But the resolveComponentFactory method only consumes Components not strings. So I want to try to get the specific component out of the entryComponents list. – Zteve Nov 07 '16 at 14:30
  • 1
    I'm not sure how this should work together in your case, but I guess that you need a service that maps strings to relevant component classes, like [this one](http://stackoverflow.com/a/40063568/3731501) – Estus Flask Nov 07 '16 at 15:24
  • Thank you, that solved my issue! – Zteve Nov 07 '16 at 15:50

0 Answers0