Angular 为什么在类内声明@Input和@Output修饰符?为什么不像@Component那样在类之外呢?

Angular 为什么在类内声明@Input和@Output修饰符?为什么不像@Component那样在类之外呢?,angular,angular-decorator,Angular,Angular Decorator,有人能解释为什么@Input和@output修饰符在类内声明,我们不能像@Component那样在类外声明吗 import { Component, Input } from '@angular/core'; @Component({ selector: 'my-component', }) class MyComponent { @Input() name: string; @Input() age: number; @Output() onP

有人能解释为什么
@Input
@output
修饰符在类内声明,我们不能像
@Component
那样在类外声明吗

import { Component, Input } from '@angular/core';

@Component({ 
    selector: 'my-component', 
})

class MyComponent {  
    @Input() name: string;  
    @Input() age: number;

    @Output() onProductSelected: EventEmitter<Product>;
}
从'@angular/core'导入{Component,Input};
@组件({
选择器:“我的组件”,
})
类MyComponent{
@Input()名称:string;
@输入()年龄:数字;
@Output()onProductSelected:EventEmitter;
}

装饰器不是独立的实体,它们装饰其他实体

对于输入和输出,它们是修饰类成员变量


根据定义,类成员变量在类中,因此这就是装饰器必须去的地方。

因为这是合乎逻辑的事情吗?使用组件上的装饰器,您如何判断哪些字段是输入和输出?在和输出中,通过模板提供,组件外部没有可用的模板。是的,您甚至可以在方法上放置装饰器。你需要有很多装饰属性。