【问题标题】:Angular instant search only show hits when enter is pressed or with the search icon is pressedAngular 即时搜索仅在按下回车键或按下搜索图标时显示命中
【发布时间】:2020-06-10 22:23:14
【问题描述】:

我只希望在用户按下回车键或点击输入上的搜索图标时显示从 Algolia 返回的命中。我已经知道了,因此使用searchAsyouType = false 在输入时只显示特定的命中:

<ais-search-box [searchAsYouType]=false  ></ais-search-box>

但问题是,当没有输入任何内容时,默认情况下会显示所有命中,如下所示:

这是我的代码:

<ais-instantsearch [config]="searchConfig" >

  <ais-search-box [searchAsYouType]=false  ></ais-search-box>

  <ais-hits >
    <ng-template let-hits="hits">
      <div *ngFor="let hit of hits">

        <div class="bio">
          hit: {{ hit.post_code }}
        </div>

      </div>
    </ng-template>
  </ais-hits>
</ais-instantsearch>

以前有人遇到过这个问题吗?如何在按下输入/搜索图标之前隐藏所有点击?

【问题讨论】:

  • 如果在用户清空搜索栏时捕获到事件,您可以分配 this.hits = null
  • 你不能验证用户插入他的输入的输入元素是否为空,并且只有在不是时才显示(使用 *ngIf)命中?

标签: javascript angular algolia instantsearch


【解决方案1】:

假应该是“假”。或者只是删除标签,因为默认值为“false”。那会给你留下:

<ais-search-box></ais-search-box>

【讨论】:

    猜你喜欢
    • 2018-12-04
    • 2010-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多