繁体   English   中英

错误:找不到 pipe '分页'! 在 Angular 11 中使用 Ngx 分页

[英]Error: The pipe 'paginate' could not be found! with Ngx-pagination in Angular 11

我正在使用 angular 11 并尝试实现分页

HTML

 <tbody>
              <tr *ngFor="let order of orders | paginate: config;let i = index">
                <th scope="row" style="display:none;">{{ i + 1 }}</th>
                <td>{{ order.Code }}</td>
                <td>{{ order.quantity }}</td>
              </tr>
           </tbody>
          </table>
          <pagination-controls id="basicPaginate" (pageChange)="pageChanged($event)"></pagination-controls>

app.module.ts

......

import { NgxPaginationModule } from 'ngx-pagination';


  imports: [
    .......
    RouterModule.forRoot(AppRoutes,{
      useHash: true
    }),
    .......
    NgxPaginationModule
    
  ]

订单组件

export class OrderComponent implements OnInit {

orders : Order [] = [];
config:any;


  constructor(private orderService : OrderService {
    this.config = {
      id: 'basicPaginate',
      itemsPerPage: 5,
      currentPage: 1,
      totalItems: 50
    };
  }
ngOnInit(){
//web service ok
    this.orderService.getAllOrders(30,5,0).pipe(first()).subscribe(orders => this.orders = orders);

  }


  
  pageChanged(event) {
    this.config.currentPage = event;
  }


}

项目编译正常

那么为什么会出现这个错误呢? 我只想要基本的分页而不是自定义的分页。 Angular 11 是否存在兼容性问题?

我希望您找到解决问题的方法。 这个问题刚刚发生在我身上,我通过在导入数组的最顶部导入 NgxPaginationModule 来修复它。 之后,保留项目。 它可能会起作用。 如果没有,只需卸载并重新安装 ngx 分页。

这是在我的项目的导入数组中显示模块的 position 的图像

如果我是您,我会检查您是否已将 NgxPagination 模块正确导入到您正在使用它的模块中,如果您将其导入到模块中,请确保您正在使用的模块正在导入您正在使用的模块。 例如:

shared.module.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { NgxPaginationModule } from 'ngx-pagination'; //Imports NgxPaginationModule 

@NgModule({
  declarations: [],
  imports: [CommonModule, NgxPaginationModule ],
  exports: [CommonModule, NgxPaginationModule], // Exports NgxPaginationModule 
})
export class SharedModule {}

为了在以下模块中使用它,您必须导入第 7 行中表示的 SharedModule(带有注释的行)

产品-feature.module.ts

import { NgModule } from '@angular/core';
import { ProductComponent } from '../product/product.component';
import { SharedModule } from '../shared/shared.module';

@NgModule({
  declarations: [ProductComponent],
  imports: [SharedModule], //must import SharedModule
  exports: [ProductComponent],
})
export class ProductsFeatureModule {}

这似乎是一个 VS Code(假设你使用它)故障。 只需重新启动您的 IDE 并重试。

PS:如果您的 OrderComponent 位于不同的模块中,那么您还需要在该模块的导入部分中使用NgxPaginationModule

  1. Go 到您的OrderComponent导入的模块文件yourModuleName.module.ts并添加以下代码

 import { NgxPaginationModule } from 'ngx-pagination'; // At the top of your module. . . @NgModule({ imports: [ CommonModule, NgxPaginationModule // Add this line of code here ],

  1. 重新编译您的项目,它将正常工作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM