Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with same Pipe component declarations in child modules

I want to declare pipe in parent module and use it in child modules.

@NgModule({
  // Pipe which I want to declare in all child modules
  declarations: [ ThisIsPipe ],
  imports: [ ChildModuleOne, ChildModuleTwo],  
})

How can I use It child modules?

Because if I declare it twice I got error

Uncaught Error: Type ThisIsPipe is part of the declarations of 2 modules: ChildModuleOne and ChildModuleTwo! Please consider moving ThisIsPipe to a higher module that imports ChildModuleOne and ChildModuleTwo. You can also create a new NgModule that exports and includes ThisIsPipe then imports that NgModule in ChildModuleOne and ChildModuleTwo.

like image 796
Max K Avatar asked Sep 29 '16 16:09

Max K


1 Answers

You need to create another module where you put the pipe and then import that module where you want to use that pipe.

One directive, component, or pipe can always belong only to exact one NgModule but this NgModule can be imported to as many modules as desired.

like image 189
Günter Zöchbauer Avatar answered Oct 02 '22 16:10

Günter Zöchbauer