I want to get the metadata for the current NgModule in order to get the list of declarations
and providers
in order to fill in a dynamic module I create to display components in a modal.
How can that be done?
You can access the declarations using the reflect-metadata
package. You do however need to install this package and include it in your project. After that you can get the annotations like this:
let annotations: DecoratorFactory[] = Reflect.getMetadata('annotations', ModuleClass);
If the @NgModule
is the only annotation on there, which I would guess it is, you can access the declarations like this, otherwise you have to guess the right index
:
let declarations: any[] = annotations[0].declarations;
See this answer for further reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With