Angular 如何在NG4中使用带分页的搜索管道

Angular 如何在NG4中使用带分页的搜索管道,angular,search,pagination,pipe,Angular,Search,Pagination,Pipe,我有下面的搜索管道代码 import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'pkhospitalparam' }) export class PkhospitalparamPipe implements PipeTransform { transform(value: any[], searchString: string ) { if (!searchString) { con

我有下面的搜索管道代码

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

@Pipe({
  name: 'pkhospitalparam'
})
export class PkhospitalparamPipe implements PipeTransform {

  transform(value: any[], searchString: string ) {

    if (!searchString) {
      console.log('no search');
      return value;
    }

    return value.filter(it => {
        const hospitalName = it.name.toLowerCase().includes(searchString.toLowerCase());

        return (hospitalName);
    });
 }

}
HTML:



我已经通过了ngFor中的管道参数,工作正常。问题是,因为我已经实现了分页(大约50页),所以总共50页的搜索不会发生。仅在我所在的页面上搜索筛选器。是否有对所有页面进行全局搜索的方法?

这是一个非常古老的方法,但可能对其他人有所帮助

通过使用w-ng5组件为我工作

1) 通过npm安装

npm install w-ng5 --save
2) 在app.module.ts中安装导入模块后

import { PipesModule } from 'w-ng5';
3) app.module.ts的加载项导入部分

imports: [
    PipesModule,
 ]
4) 现在您可以使用

<input type="text" class="form-control" [(ngModel)]="searchHospitalParam"/>
   <div *ngFor="let result of resultArray | filter:searchHospitalParam" | paginate: { itemsPerPage: 5, currentPage: p } | ></div>


*注意:在分页之前,您应该先进行筛选

我们也可以看到分页管道吗?在对数据进行分页和筛选时,您应该先过滤数据,然后对其进行分页,而不是相反。因为在你对它分页之后,你手头没有完整的数据来过滤它。太好了!!它工作了嗨,我有点小错误,因为当我使用
w-ng5
时,它没有以正确的方式过滤,只显示一个空白列表,你能帮我解决这个问题吗?你能发布一个新的问题来描述你遇到的麻烦吗嘿,兄弟,这是,问候!
<input type="text" class="form-control" [(ngModel)]="searchHospitalParam"/>
   <div *ngFor="let result of resultArray | filter:searchHospitalParam" | paginate: { itemsPerPage: 5, currentPage: p } | ></div>