Angular2 @输入到具有get/set的属性

我在该组件中有一个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();
}
您可以直接在setter上设置@Input,如下所述:
_allowDay: boolean;
get allowDay(): boolean {
    return this._allowDay;
}

@Input('allowDay')
set allowDay(value: boolean) {
    this._allowDay = value;
    this.updatePeriodTypes();
}

看到这个plunkr:https://plnkr.co/edit/6miSutgTe9sfEMCb8N4p?p=preview

相关文章

ANGULAR.JS:NG-SELECTANDNG-OPTIONSPS:其实看英文文档比看中...
AngularJS中使用Chart.js制折线图与饼图实例  Chart.js 是...
IE浏览器兼容性后续前言 继续尝试解决IE浏览器兼容性问题,...
Angular实现下拉菜单多选写这篇文章时,引用文章地址如下:h...
在AngularJS应用中集成科大讯飞语音输入功能前言 根据项目...
Angular数据更新不及时问题探讨前言 在修复控制角标正确变...