Angular 我如何修复错误;错误:管道';过滤器';找不到!错误:管道';过滤器';找不到&引用;10分钟?
我有一个过滤器,当搜索一个名称时,它会给我带来包含该名称的数据,但它只会在浏览器控制台中向我发送该错误。 它只是没有显示页面Angular 我如何修复错误;错误:管道';过滤器';找不到!错误:管道';过滤器';找不到&引用;10分钟?,angular,typescript,pipe,Angular,Typescript,Pipe,我有一个过滤器,当搜索一个名称时,它会给我带来包含该名称的数据,但它只会在浏览器控制台中向我发送该错误。 它只是没有显示页面 html 烟斗 我真的不知道问题是否在这里 import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'filtro' }) export class FiltroPipe implements PipeTransform { transform(value: any, arg: a
html
烟斗
我真的不知道问题是否在这里
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'filtro'
})
export class FiltroPipe implements PipeTransform {
transform(value: any, arg: any): any {
if (arg === '' || arg.length < 3) return value;
const resultPosts = [];
for (const post of value) {
if (post.email.toLowerCase().indexOf(arg.toLowerCase()) > -1) {
resultPosts.push(post);
};
};
return resultPosts;
}
}
您需要在
组件类型脚本
文件的提供程序中注册FiltroPie。
然后它就会工作。您必须将其导入最近的模块
或app.module.ts
在HTML中使用管道时,请在声明中插入管道(例如|“pipename”)
在.ts文件中使用管道时,请在提供程序中插入管道(例如pipename.transform()
)
你是如何在你的模块中导入它的?在app.module.ts中,我把{FilterPipe}从“./pipes/filtro.pipe.”
导入,在声明“FilterPipe”中,@DEXcarlos,它并不总是app.module.ts,离你正在使用该管道的组件最近的模块是什么。我修复了它。是在contact.module.ts
filterPost = '';
`````````
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'filtro'
})
export class FiltroPipe implements PipeTransform {
transform(value: any, arg: any): any {
if (arg === '' || arg.length < 3) return value;
const resultPosts = [];
for (const post of value) {
if (post.email.toLowerCase().indexOf(arg.toLowerCase()) > -1) {
resultPosts.push(post);
};
};
return resultPosts;
}
}
import {FormsModule} from '@angular/forms';
import { FiltroPipe } from './pipes/filtro.pipe'
@NgModule({
declarations: [
FiltroPipe,
AppComponent,
SendEmailComponent,
NavbarComponent,
SidebarComponent,
InactivityTimerComponent,
],
imports: [
BrowserModule,
AppRoutingModule,
ReactiveFormsModule,
AngularFireModule.initializeApp(environment.firebaseConfig),
AngularFirestoreModule,
AngularFireAuthModule, FormsModule
],
providers: [AuthService, CanPaginaPrincipalGuard, AngularFirestore,DataDbService,
],
bootstrap: [AppComponent]
})
export class AppModule { }
@NgModule({
// ---,
declarations:[],
// ----,
@NgModule({
// ----,
providers:[],
// ----