我想在父模塊中聲明管道並在子模塊中使用它。在子模塊中使用相同的管道組件聲明問題
@NgModule({
// Pipe which I want to declare in all child modules
declarations: [ ThisIsPipe ],
imports: [ ChildModuleOne, ChildModuleTwo],
})
如何使用它的子模塊?
因爲如果我聲明它兩次我有錯誤
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.
是否可以使用父母的聲明從子模塊? –
不,您必須直接導入要使用聲明的所有模塊。你可以將幾個可重用的組件,指令和管道放在一起成爲一個NgModule。您還可以創建一個NgModule(A),導出其他NgModules(B,C,D),以便通過將A添加到當前模塊的導入來導入B,C,D。 –