2017-07-19 37 views
1

在app.module.ts中聲明的App Ionic 2指令中。Ionic 3中的指令

但是在Ionic 3(延遲加載)中,此指令不起作用。 我嘗試組件模塊中輸入指令,例如:

... 
import { TabindexDirective } from '../../../app/tabindex.directive'; 

@NgModule({ 
    declarations: [ 
    ... 
    TabindexDirective, 
    ], 
    imports: [ 
    ... 
    ], 
    exports: [ 
    ... 
    ], 
}) 
export class SignupModule {} 

此代碼工作正常,但後來我輸入這個指令在另一個組件模塊,我有錯誤:

Type GoComponent is part of the declarations of 2 modules: SignupModule and AddPageModule! Please consider moving GoComponent to a higher module that imports

如何修復並在Ionic 3中使用指令?

+0

[離子3周的iOS可能重複建設--prod不工作:聲明的2模塊錯誤](https://stackoverflow.com/questions/46840108/ionic-3-ios-build-prod-not-working-declarations-of-2-modules-error) –

回答

0

在Ionic 3內部使用的Angular 2及更高版本中,指令或組件不能在兩個模塊中聲明。

您需要創建一個通用模塊,其中需要在其他模塊中重用的所有組件都應聲明。 然後,您可以將該通用模塊導入任何您希望使用該組件的模塊中。

0

我嘗試在--prod模式下構建時,最近遇到了與使用Angular組件相同的錯誤。我終於通過從某些指令和組件中刪除.module.ts文件來修復它。

我將您的問題標記爲重複,因此請將您的問題重定向到this link以解決您的問題。

0

我不想重複我的答案,但這裏的理念是:

import { IonicModule; IonicPageModule } from 'ionic-angular'; 
import { MyApp } from './app.component'; 
import { MyComponent } from '../directives/my-directive/my-directive'; 

@NgModule({ 
    imports: [ 
    IonicModule.forRoot(MyApp), 
    IonicPageModule.forChild(MyComponent) // Here 
    ], 
    declarations: [MyApp, MyComponent] 
}) 

原來的答覆:https://stackoverflow.com/a/47253126/1311952