@Input和其他装饰器及继承 [英] @Input and other decorators and inheritance
问题描述
我真的不了解对象绑定的工作原理,所以如果有人可以解释我是否可以在基类或更好的类中使用@Input():装饰器和继承. 例如,如果每个表格都应接待客户,则我有一个基类:
I don't really understand how object binding works, so if anyone could explain if I can use @Input() inside a base class, or better: decorators and inheritance. For example if each form should receive a customer I have a base class:
export class AbstractCustomerForm{
@Input() customer;
...
}
然后我在一个实际的组件中扩展此类:
and then I extend this class in an actual component:
export AwesomeCustomerForm extends AbstractCustomerForm implements OnInit{
ngOnInit(){
if(this.customer)
doSomething();
}
}
但这是行不通的,客户将永远不会被设置:(
but this won't work, customer will never get set :(
推荐答案
更新
原始
装饰器不会被继承.它们需要直接应用于用作组件的类.子类上的装饰器将被忽略.我已经看到它提到@Input()
或@Output()
在只有超类有它们而子类没有的情况下才起作用.
Decorators are not inherited. They need to be applied to the class used as component directly. Decorators on subclasses are ignored. I have seen it mentioned that @Input()
or @Output()
are working if only the super class has them and the sub-class has none.
- https://github.com/angular/angular/issues/5794
- https://github.com/angular/angular/issues/5415
- https://github.com/angular/angular/issues/7191
- https://github.com/angular/angular/issues/5794
- https://github.com/angular/angular/issues/5415
- https://github.com/angular/angular/issues/7191
这篇关于@Input和其他装饰器及继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!