找不到管道“ searchfilter”

时间:2018-11-25 20:22:19

标签: angular ionic3 angular5 ionic4

我有自定义管道并使用离子4

 ERROR Error: Uncaught (in promise): Error: Template parse errors:
The pipe 'searchfilter' could not be found ("
  </ul>
   -->
  <ion-card class="card-ios" *ngFor="let[ERROR ->] row of shopList | searchfilter : query">
    <ion-item>
  1. AppModule.ts

    import { SearchfilterPipe } from './pipes/search/searchfilter.pipe';
    
    @NgModule({declarations: [SearchfilterPipe])
    
  2. Searchfilter.Pipe.ts

    import { Pipe, PipeTransform } from '@angular/core';
    
    @Pipe({
        name: 'searchfilter'
    })
    export class SearchfilterPipe implements PipeTransform {
    
        transform(value: any, query: string): any {
            return null;
        }
    
    }
    
  3. HTML

    *ngFor="let row of shopList | searchfilter : query"
    

1 个答案:

答案 0 :(得分:1)

您还需要在app.module.ts中导出管道。 像这样:

import { SearchfilterPipe } from './pipes/search/searchfilter.pipe';

@NgModule({
    declarations: [SearchfilterPipe],
    exports: [SearchfilterPipe]
)

我希望这会对您有所帮助。