我在该组件中有一个Angular2组件,它当前有一堆字段,这些字段前面应用了@Input(),以允许绑定到该属性,即.
@Input() allowDay: boolean;
我想做的实际上是用get/set绑定到一个属性,这样我就可以在setter中执行其他一些逻辑,比如
_allowDay: boolean;
get allowDay(): boolean {
return this._allowDay;
}
set allowDay(value: boolean) {
this._allowDay = value;
this.updatePeriodTypes();
}
在Angular2我该怎么做?
根据Thierry Templier的建议,我将其更改为,但这会引发错误,无法绑定到"allowDay",因为它不是已知的本机属性:
//@Input() allowDay: boolean;
_allowDay: boolean;
get allowDay(): boolean {
return this._allowDay;
}
@Input('allowDay') set allowDay(value: boolean) {
this._allowDay = value;
this.updatePeriodTypes();
}