错误 --> 使用 angular4 时找不到管道“过滤器”

7 angular

我正在 angular4 -node.js 部署项目中进行单元测试。在测试时我发现了这个错误 -

Template parse errors:
The pipe 'filter' could not be found ("
  </thead>
  <tbody>
    <tr *ngFor="let[ERROR ->] dat of result | filter:filterdata| 
paginate: { itemsPerPage: 5, currentPage: p };let i = index ">
Run Code Online (Sandbox Code Playgroud)

所以我将这两个模块添加到我的 module.ts 和 spec.ts 文件中 -->

import { PipesModule } from '../../pipes/pipes.module';
import { Pipe, PipeTransform } from '@angular/core';

@NgModule({
 imports: [PipesModule
 ],
Run Code Online (Sandbox Code Playgroud)

对于这个特定的模块导入 -->

import { PipesModule } from '../../pipes/pipes.module';
Run Code Online (Sandbox Code Playgroud)

错误 --> 找不到模块“../../pipes/pipes.module”。

请帮助解决问题

Phi*_*hil 6

您必须在 PipesModule 的声明和导出中包含 FilterPipe。

  • 你能详细说明一下吗 (13认同)

7gu*_*uyo 5

Angular 7/8 - 嵌套路线

如果您使用一些嵌套路由并且在子组件中使用过滤器,请从 app.modules.ts 中删除过滤器并:

对于自定义过滤器

在子 childmodule.module.ts 的声明部分导入过滤器

对于 ng2-搜索过滤器

在子 childmodule.module.ts 的导入部分导入 Ng2SearchPipeModule