Angular2:向子类中继承的装饰器添加装饰器

Angular2:向子类中继承的装饰器添加装饰器,angular,inheritance,decorator,angular-decorator,angular2-inputs,Angular,Inheritance,Decorator,Angular Decorator,Angular2 Inputs,我的Angular2项目中有以下代码: @Component({selector: 'foo'}) export class Foo { @Input() protected field:any; } @Component({selector: 'bar'}) export class Bar extends Foo { ngOnInit(): void { if (this.field) { // do something

我的Angular2项目中有以下代码:

@Component({selector: 'foo'})
export class Foo {
    @Input() protected field:any;
}

@Component({selector: 'bar'})
export class Bar extends Foo {
    ngOnInit(): void {
        if (this.field) {
            // do something
        }
    }
}
在这种情况下,所有的工作都像一个符咒:
字段
成功地设置在组件“栏”中

但是如果我尝试向子组件添加一个或多个
Input
,它将不起作用。以下是新代码:

@Component({selector: 'foo'})
export class Foo {
    @Input() protected field:any;
}

@Component({selector: 'bar'})
export class Bar extends Foo {
    @Input() private anotherField:any;

    ngOnInit(): void {
        if (this.field) {
            // do something
        }
    }
}
在这种情况下,我得到以下错误:

未处理的承诺拒绝:模板分析错误: 无法绑定到“field”,因为它不是“bar”的已知属性。

似乎设置新的Decorator变量(
anotherField
)会隐藏继承的Decorator变量。我说得对吗

那么,如何将一个或多个Decorator变量添加到扩展具有自己的Decorator的类的类中呢


编辑:我目前正在使用angular2.4.2。

您使用的是angular2的哪个版本?我正在使用VersionOne 2.4.2,您在模板文件中绑定到
字段的位置:
@smartmouse这就是我询问您的版本的原因,因为这应该在
2.3.0
之后才能工作。看见我刚刚在
4.0.0-beta.7上测试了您的示例代码,没有发现错误