angular - Typescript @Component "Decorator"是否与装饰器模式有关?

标签 angular typescript decorator angular-decorator typescript-decorator

@Component({})组件 .ts 文件中的行称为装饰器。这与装饰者模式有关,还是无关?

最佳答案

它们是相关的,因为您使用附加功能装饰现有类。它们不一样,因为 typescript @Decorator在编译时应用,而装饰器模式也可用于在运行时装饰类,例如:

let armoredenemy = new Armored(new Enemy())
let enemy = new Enemy()

在程序运行时,您仍然可以决定是否要装饰一个类。

关于angular - Typescript @Component "Decorator"是否与装饰器模式有关?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52409188/

相关文章:

angular - 路由器链接不适用于共享模块内的组件

javascript - 为什么 "script"内的代码在 html 中不起作用?

python - 修改django装饰器函数,Permissionn_required

python - 当 @mock.patch 装饰器在 Python 中的装饰方法/函数的参数数量多时,它会做什么?

angular - 从数组循环渲染组件

angular - 如何使用 typescript 重新渲染多个数据表?

http - Angular2.1 无法读取未定义的属性 'get'

typescript - 每个类的文件方法和模块内部类

javascript - React TypeScript 从点击事件中获取数据属性

php - 自定义表单装饰器中的 Zend 框架类