首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ngx分页中过滤器的制作

ngx分页中过滤器的制作
EN

Stack Overflow用户
提问于 2019-03-19 21:58:07
回答 2查看 4.4K关注 0票数 0

在角7+电子4中,我使用ngx分页,但不能解决滤波器的问题.

我像在文档中那样做,但是我得到了错误未明错误:模板解析错误:管道'stringFilter‘无法找到

请帮帮我。提前感谢

Html-1:

代码语言:javascript
复制
<input
  type="text"
  name="search"
  class="search__input"
  placeholder="Search by Name..."
  [(ngModel)]="tableService.filter"> 

Html-2:

代码语言:javascript
复制
<ul class="table-body__list">
 <li *ngFor="let item of tableService.items | stringFilter: tableService.filter | paginate: config">
   <app-item [item]="item"></app-item>
 </li>
</ul>

<pagination-controls
  [maxSize]="maxSize"
  directionLinks="true"
  responsive="true"
  previousLabel="Previous page"
  nextLabel="Next page"
  (pageChange)="onPageChange($event)">        
</pagination-controls>

TypeScript:

代码语言:javascript
复制
import { Component, OnInit } from '@angular/core';
import { PaginationInstance } from 'ngx-pagination';
import { TableService } from '../../services/table.service';
@Component({
  selector: 'app-jobs-table',
  templateUrl: './jobs-table.component.html',
  styleUrls: ['./jobs-table.component.scss']
})
export class JobsTableComponent implements OnInit {
  filter = '';
  maxSize = 9;
  config: PaginationInstance = {
    itemsPerPage: 11,
    currentPage: 1
  };

  constructor(public tableService: TableService) { }

  ngOnInit() {
  }

  onPageChange(number: number) {
    this.config.currentPage = number;
  }

}

在TableService中:

代码语言:javascript
复制
filter = '';
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-03-19 22:41:57

如在github (搜索存储库中的筛选器)上所发现的那样。很明显,npx分页并没有任何标准的过滤管道。他们的医生..。次优

代码语言:javascript
复制
import {Pipe} from "@angular/core";

/**
 * A simple string filter, since Angular does not yet have a filter pipe built in.
 */
@Pipe({
    name: 'stringFilter'
})
export class StringFilterPipe {

    transform(value: string[], q: string) {
        if (!q || q === '') {
            return value;
        }
        return value.filter(item => -1 < item.toLowerCase().indexOf(q.toLowerCase()));
    }
}

有趣的评论顺便说一句:由于性能原因,用于过滤的角移除管。

票数 1
EN

Stack Overflow用户

发布于 2020-11-07 12:57:50

只能使用筛选器更改stringFilter。

代码语言:javascript
复制
<ul class="table-body__list">
 <li *ngFor="let item of tableService.items | filter: tableService.filter | paginate: config">
   <app-item [item]="item"></app-item>
 </li>
</ul>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55250595

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档