我想在@Input()cleanTextBox上执行doClean()函数
@Component({
selector: 'my-component',
providers: [],
template: `<input [(ngModel)]="abc">`,
directives: []
})
export class Directive {
@Input() cleanTextBox : boolean;
public abc = "someValue";
// Execute doClean function if cleanTextBox is true
public doClean{
this.abc = '';
}
}
最佳答案
您可以使用二传手
export class Directive {
private _cleanTextBox: boolean;
@Input() set cleanTextBox(value: boolean) {
if (value) {
this.doClean();
}
this._cleanTextBox = value;
}
get cleanTextBox() {
return this._cleanTextBox;
}
public abc = "someValue";
public doClean{
this.abc = '';
}
}