The pipe ' ' could not be found angular2 custom pipe

后端 未结 9 1131
时光说笑
时光说笑 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:54

    Suggesting an alternative answer here:

    Making a separate module for the Pipe is not required, but is definitely an alternative. Check the official docs footnote: https://angular.io/guide/pipes#custom-pipes

    You use your custom pipe the same way you use built-in pipes.
    You must include your pipe in the declarations array of the AppModule . If you choose to inject your pipe into a class, you must provide it in the providers array of your NgModule.

    All you have to do is add your pipe to the declarations array, and the providers array in the module where you want to use the Pipe.

    declarations: [
    ...
    CustomPipe,
    ...
    ],
    providers: [
    ...
    CustomPipe,
    ...
    ]
    

提交回复
热议问题