Read TypeDecorator from Angular 5 Components

I used to be able to get metadata for a component with Reflect metadata. Now the metadata has been transferred to some annotations attached to the component.

Reading metadata per se

type['__annotations__'][0].selector

- This is certainly a hack. What is the correct method for reading such metadata from a component? I want to get data attached to a component in a decorator @Component.

+4
source share
1 answer

If you need a selector, this is a great way to get it.

constructor(public elementRef: ElementRef<any>) {}
...
const nodeName = this.elementRef.nativeElement.nodeName.toLowerCase();
...

I have a component that can be declared as an element or as an attribute. This approach lets me know if the host element is a div element (when my component is an attribute) or my component selector.

0
source

Source: https://habr.com/ru/post/1688765/


All Articles