角滤管工作不正常

问题

我的数据库中有两个不同的列中有名字和姓氏,所以我必须以这种方式绑定它以在我的表中显示为 1。

但是,当我在名字和姓氏之间输入空格时,我的搜索功能不起作用:

<tbody>
    <tr *ngFor="let e of employeelist | filter : searchByName">
        <td>{{e.firstName}} {{e.lastName}}</td>


 import { Injectable, Pipe, PipeTransform } from '@angular/core';

  @Pipe({
    name: 'filter'
   })

   @Injectable()
  export class FilterEmployeesPipe implements PipeTransform {
      transform(value: any, input: string) {
    if (input) {
   input = input.toLowerCase();
   //filter je filter() metod iz array.prototype.filter
   return value.filter(function (employee: any) {

       return ((employee.firstName.toLowerCase().indexOf(input)) && 
     (employee.lastName.toLowerCase().indexOf(input))) > -1;
      })
   }
   return value;
    }
     }
君特·佐希鲍尔

您需要在用于匹配输入的字符串中包含空格

return (employee.firstName.toLowerCase() + ' ' employee.lastName.toLowerCase()).indexOf(input) > -1;

否则你就是在比较苹果和梨。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章