The pipe ' ' could not be found angular2 custom pipe

后端 未结 9 1103
时光说笑
时光说笑 2020-11-27 14:33

I can\'t seem to fix this error. I have a search bar and an ngFor. I am trying to filter the array using a custom pipe like this:



        
9条回答
  •  自闭症患者
    2020-11-27 14:57

    Make sure you are not facing a "cross module" problem

    If the component which is using the pipe, doesn't belong to the module which has declared the pipe component "globally" then the pipe is not found and you get this error message.

    In my case I've declared the pipe in a separate module and imported this pipe module in any other module having components using the pipe.

    I have declared a that the component in which you are using the pipe is

    the Pipe Module

     import { NgModule }      from '@angular/core';
     import { myDateFormat }          from '../directives/myDateFormat';
    
     @NgModule({
         imports:        [],
         declarations:   [myDateFormat],
         exports:        [myDateFormat],
     })
    
     export class PipeModule {
    
       static forRoot() {
          return {
              ngModule: PipeModule,
              providers: [],
          };
       }
     } 
    

    Usage in another module (e.g. app.module)

      // Import APPLICATION MODULES
      ...
      import { PipeModule }    from './tools/PipeModule';
    
      @NgModule({
         imports: [
        ...
        , PipeModule.forRoot()
        ....
      ],
    

提交回复
热议问题