Angular 角/铬:管道';过滤器';找不到

Angular 角/铬:管道';过滤器';找不到,angular,typescript,google-chrome,filter,pipe,Angular,Typescript,Google Chrome,Filter,Pipe,虽然这个话题出现过几次,但我发现解决方案并不令我满意。因此,我有以下几点: play.module.ts import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { Ng2SearchPipeModule } from 'ng2-search-fi

虽然这个话题出现过几次,但我发现解决方案并不令我满意。因此,我有以下几点:

play.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { Ng2SearchPipeModule } from 'ng2-search-filter';

import { PlayComponent } from './play.component';

@NgModule({
  imports:      [ BrowserModule, FormsModule, Ng2SearchPipeModule ],
  declarations: [ PlayComponent ],
  bootstrap:    [ PlayComponent ],
  providers:    [ Ng2SearchPipeModule ]
})
export class PlayModule { }
play.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'play',
  templateUrl: './play.component.html',
  styleUrls: [ './play.component.scss' ]
})
export class PlayComponent  {
  name = 'Angular';
  items = ["Kyle","Eric","Bailey", "Deborah", "Glenn", "Jaco", "Joni", "Gigi"]
  term: string;
}
play.component.html:

<div>
        <input type="text" [(ngModel)]="term" >
        <div *ngFor = "let item of items | filter:term" >
          <p>
            {{item}}
          </p>
        </div>
     </div> 


{{item}}

现在,在Chrome中,错误消息如下:

The pipe 'filter' could not be found ("
    <div>
        <input type="text" [(ngModel)]="term" >
        <div *ngFor = "le[ERROR ->]t item of items | filter:term" >
          <p>
            {{item}}
"): ng:///ReportsModule/playComponent.html@5:25
Error: Template parse errors:
The pipe 'filter' could not be found ("
    <div>
        <input type="text" [(ngModel)]="term" >
        <div *ngFor = "le[ERROR ->]t item of items | filter:term" >
          <p>
            {{item}}
"): ng:///ReportsModule/PlayComponent.html@5:25
找不到管道“筛选器”(“

{{item}}
“”:ng:///ReportsModule/playComponent。html@5:25
错误:模板分析错误:
找不到管道“筛选器”(“

{{item}}
“”:ng:///ReportsModule/PlayComponent。html@5:25

有人能看到我遗漏了什么吗?

您不必将
Ng2SearchPipeModule
添加到
提供者
数组中

您的play.module.ts应为:

从'@angular/core'导入{NgModule};
从“@angular/platform browser”导入{BrowserModule};
从'@angular/forms'导入{FormsModule};
从“ng2搜索筛选器”导入{Ng2SearchPipeModule};
从“/play.component”导入{PlayComponent};
@NGD模块({
导入:[BrowserModule、FormsModule、Ng2SearchPipeModule],
声明:[PlayComponent],
引导:[播放组件]
})
导出类PlayModule{}

这是一个有效的

程序,您不必将
Ng2SearchPipeModule
添加到
提供程序
数组中

您的play.module.ts应为:

从'@angular/core'导入{NgModule};
从“@angular/platform browser”导入{BrowserModule};
从'@angular/forms'导入{FormsModule};
从“ng2搜索筛选器”导入{Ng2SearchPipeModule};
从“/play.component”导入{PlayComponent};
@NGD模块({
导入:[BrowserModule、FormsModule、Ng2SearchPipeModule],
声明:[PlayComponent],
引导:[播放组件]
})
导出类PlayModule{}

这是一个有效的

您可以从提供者数组中删除模块吗?您是否尝试将
Ng2SearchPipeModule
添加到
app.module
(在
imports
数组中)而不是
PlayModule
?。只是为了验证,两者都做了,并且出现了相同的错误。谢谢,找到原因了。需要在根模块中导入Ng2SearchPipeModule。能否从提供程序数组中删除该模块?是否尝试将
Ng2SearchPipeModule
添加到
app.module
(在
imports
数组中)而不是
PlayModule
?。只是为了验证,两者都做了,并且出现了相同的错误。谢谢,找到原因了。Ng2SearchPipeModule需要导入到根模块中。检查链接中的代码,它可以正常工作,没有任何错误。将
Ng2SearchPipeModule
添加到导入中,就像在代码段中一样。事实上,这段代码是从链接复制的,但它对我不起作用。谢谢,找到原因了。Ng2SearchPipeModule需要导入到根模块中。检查链接中的代码,它可以正常工作,没有任何错误。将
Ng2SearchPipeModule
添加到导入中,就像在代码段中一样。事实上,这段代码是从链接复制的,但它对我不起作用。谢谢,找到原因了。需要在根模块中导入Ng2SearchPipeModule。