首页 > 解决方案 > Angular(keyup)事件仅检测到 # 符号

问题描述

我试图使用角度(keyup)事件来实现搜索栏。我的文件名像

当我在搜索栏中搜索 base @ 或 base $ 或 base 1 时,它会很好地过滤。但是当我搜索 base # 它不过滤 base # 它会过滤所有带有 base 的文件名。这是我编写的代码

我的html:

<input type="search" class="form-control" placeholder="Search file" (keyup)="onSearch($event)" [(ngModel)]='searchKeywords'>

我的js代码:

onSearch(event: any) {
    const keywords = event.target.value;
    if (keywords && keywords.length > 2) {
          const apiURL =`abc/thg/hjy?filter[file.name]=${keywords}`;
          this.api.get(apiURL).subscribe((data: any) => {
            console.log(data);
            this.topics = data.list;
            if (this.trigger) {
            this.trigger.openMenu();
            }
         });
    } else {
        this.topics = [];
        this.trigger.closeMenu();
    }
}

标签: htmlangular

解决方案



现在我可以通过了#

onSearch(event: any) {
  const keywords = event.target.value;
  const params: any = {};
  if (keywords && keywords.length > 2) {
    params['filter[translations.title]'] = keywords;
    const options = {
      search: params
    };
    const apiURL = `abc/thg/hjy`;
    this.api.get(apiURL, options).subscribe((data: any) => {
      console.log(data);
      this.topics = data.list;
      if (this.trigger) {
        this.trigger.openMenu();
      }
    });
  } else {
    this.topics = [];
    this.trigger.closeMenu();
  }
}

推荐阅读