数组中的Angular5自动完成搜索

时间:2018-07-25 08:28:59

标签: autocomplete angular5 searchfiltercollection

我正在构建用于查找城市的过滤器。 我有一个带有城市名称的数组。 (this.place = [伦敦,阿姆斯特丹,罗马,巴黎])

当用户在要在数组中搜索并输入建议列表的输入字段中输入字母时,我会有一个输入字段。

我尝试了此方法,但是它不起作用:

Html:
    <input #inputValue (keyup)="filterValues($event)" />
            <div *ngIf='placesFound'>
            <span *ngFor="let place of placesFound">
              {{place}}
            </span>
        </div>

TS file:

  filterValues(event) {


    let key = event.key
   this.placesFound = this.places.filter(function(event) {
      return this.places.indexOf(key) > -1
    })

  }

这不起作用,有人有什么建议吗?

thx!

0 个答案:

没有答案