我想在@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 = '';
}
}
答案 0 :(得分:1)
你可以使用setter
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 = '';
}
}