gpt4 book ai didi

angular - 从 Angular 5 组件中读取 TypeDecorator

转载 作者:太空狗 更新时间:2023-10-29 18:01:18 25 4
gpt4 key购买 nike

以前,我能够使用 Reflect 元数据获取组件的元数据。现在元数据已移动到附加到组件的一些注释。

读取元数据

type['__annotations__'][0].selector

绝对是一个 hack。从组件中读取此类元数据的正确方法是什么?我想获取附加到 @Component 装饰器中组件的数据。

最佳答案

如果您需要的是选择器,这是获得它的好方法。

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

我有一个组件可以声明为元素或属性。这种方法让我知道宿主元素是一个 div(当我的组件是一个属性时)还是我的组件的选择器。

关于angular - 从 Angular 5 组件中读取 TypeDecorator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47124965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com