【发布时间】:2018-08-24 21:28:52
【问题描述】:
我正在尝试使用 TypeScript 装饰器将具有动态值的属性添加到类中。 我使用 TS 文档中的以下代码:
function classDecorator<T extends {new(...args:any[]):{}}>(constructor:T) {
return class extends constructor {
newProperty = "new property";
hello = "override";
}
}
这是可行的,但这些属性的值不是动态的。我们可以向这个函数传递一个参数吗?像这样:
@classDecorator('myArgument')
之后我想在 html 文件中使用myArgument。
【问题讨论】:
标签: angular typescript decorator