删除字符时,TypeAhead不会在第一次加载

时间:2019-06-11 07:17:45

标签: angular bootstrap-4 typeahead.js

当我开始用TypeAhead书写时,选项列表有效,但如果删除字符,则总是出现上一次查找的结果。

<input id="OficinaContablePT"
   type="text"
   class="form-control"
   [(ngModel)] = "model"
   [ngbTypeahead]="searchOC"
   [inputFormatter]="formatter"
   [resultFormatter]="formatter"/>

searchOC = (text$: Observable<string>) =>
  text$.pipe(
    debounceTime(100),
    distinctUntilChanged(),
    map(term => term.length < 3 ? this.listaContables = []
        : (this.oficinaContable(1, term).filter(v => 
   v.codigo.toLocaleLowerCase().indexOf(term.toLocaleLowerCase()) > -1).slice(0, 10)))
  )

如果我寻找“ L0103”,则显示为“ L0103AZSDF,L0103QWER”,但是如果我删除一个字符(“ L010”),则必须显示为“ L0101,L0102,L0103ASDF,L010QWER”,而仅显示为“ L0103AZSDF,L0103QWER”

1 个答案:

答案 0 :(得分:0)

最后我解决了,

要解决这个问题,我需要创建一个'(ngModelChange)',用我的搜索方法为静态数组充电,然后在搜索组件中使用此数组,而不在搜索中使用该方法。