我有这种情况:期待用户的输入并将其用于来自服务器的_http.get()
。
我试过使用 keyup
事件,但无法管理。非常感谢任何建议。
我的模板:
<div class="col-md-8">
<input type="text" class="form-control" [(ngModel)]="workOrder" (keyup)="populate()" placeholder="{{ 'FIELDS.PMS_IFR_WO' | translate }}"/>
</div>
我的 ts 文件:
populate(){
console.log(this.workOrder);
this._lookup.getIcrData().subscribe(res => {
console.log(res);
});
}
最佳答案
您正在寻找 ngModelChange
:
<div class="col-md-8">
<input type="text" class="form-control" [ngModel]="workOrder" (ngModelChange)="populate($event)" placeholder="{{ 'FIELDS.PMS_IFR_WO' | translate }}"/>
</div>
组件
populate(value: any){
console.log(value);
this._lookup.getIcrData().subscribe(res => {
console.log(res);
});
}
关于angular - 通过用户在 angular2 中的输入触发方法的最佳实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47631667/