Ich habe eine Angular2-Komponente in dieser Komponente. Derzeit sind eine Reihe von Feldern mit @Input () versehen, um die Bindung an diese Eigenschaft zu ermöglichen, d. H.
@Input() allowDay: boolean;
Was ich tun möchte, ist tatsächlich mit get / set an eine Eigenschaft zu binden, damit ich im Setter eine andere Logik ausführen kann, etwa die folgende
_allowDay: boolean;
get allowDay(): boolean {
return this._allowDay;
}
set allowDay(value: boolean) {
this._allowDay = value;
this.updatePeriodTypes();
}
Wie würde ich das in Angular2 machen?
Basierend auf dem Vorschlag von Thierry Templier habe ich es geändert, aber das löst den Fehler aus. Kann nicht an 'allowDay' gebunden werden, da es keine bekannte native Eigenschaft ist:
//@Input() allowDay: boolean;
_allowDay: boolean;
get allowDay(): boolean {
return this._allowDay;
}
@Input('allowDay') set allowDay(value: boolean) {
this._allowDay = value;
this.updatePeriodTypes();
}
[allowDay]="....". If the field (setter) name and the property name you want to use for binding are the same, you can omit the parameter for@Input (...) `.