在文本框的值更改时,我正在从服务器获取数据并对其进行过滤。只要我向前输入,它就很好用,但是当我使用退格键或删除按钮时,(输入)事件会触发,但服务器调用未执行。
HTML:
<div class="searching" >
<input [readonly]="mode=='EDIT'" formControlName="userNBK" type="text"
class="form-control" (input)="getUserData(f.userNBK);" >
<div *ngIf="showSuggestions == true" (blur)="showSuggestions = false" >
<ul class="suggestionList">
<li *ngFor="let result of aitUsersList | async"
(click)="selectUserOption($event,result)" >
{{result.UserId}} | {{result.FirstName}} {{result.LastName}}
</li>
</ul>
</div>
</div>
TS:
usersList: Observable<any[]>;
getUserData(input: any) {
this.usersList =
this.manageService.getUsers("xyz")
.pipe(
map ((resp: any[]) => {
return resp.filter(u => String(u.UserId).toLowerCase().startsWith(String(input.value).toLowerCase()));
}
));