Skahrz Skahrz - 21 days ago 10
TypeScript Question

DIsplay angular 2 decorator metadata in the browser

I m learning Angular 2 internal components and behaviours, and I m having a problem while trying to display the metadata provided by the different decorators.

For example, I need to access the metadata provided by the NgModule annotation :

@NgModule({
declarations: [
/* ... */
],
imports: [
/* ... */
],
providers: [
/* ... */
],
bootstrap: [/* ... */]
})
export class AppModule { }

console.log(new AppModule());


But I can't find anything concerning the decorators metadata inside of that log information. Do you know where I can get these informations inside of my applications ?

Answer

Use reflect-metadata.

npm install --save reflect-metadata

Then import it, and use it

import 'reflect-metadata'

let metadata = Reflect.getMetadata('annotations', AppModule)