具有异步的角度可观察数组未在退格上过滤

时间:2019-03-21 16:17:42

标签: angular typescript

在文本框的值更改时,我正在从服务器获取数据并对其进行过滤。只要我向前输入,它就很好用,但是当我使用退格键或删除按钮时,(输入)事件会触发,但服务器调用未执行。

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()));
    } 
  ));

0 个答案:

没有答案