2017-07-02 67 views
2

我在離子應用程序中創建了幾頁,但在調用頁面時出現以下錯誤Uncaught (in promise): Error: No component factory found for BoxPage. Did you add it to @NgModule.entryComponents?但是我已將頁面細節添加到app.component.ts作爲import { BoxPage } from '../pages/box/box';,但問題依然存在。我已經實現了一些頁面,如家庭,產品詳細信息和購物車等,但任何新創建的頁面顯示錯誤類似的問題仍然存在其他幾個新創建的頁面。離子3中的組件問題

回答

1

就像錯誤說:

Error: No component factory found for BoxPage. Did you add it to @NgModule.entryComponents?

您需要在頁面(組件)添加到您的app.module.ts文件的@NgModule。您可以在Ionic docs找到更多的信息:

No component factory found for...

This error happens when you are trying to use a component, provider pipe or directive that has not been imported and added to your ngModule . Whenever you add a new component, provider, pipe or directive to your app, you must add it to the ngModule in the src/app/app.module.ts file for Angular to be able to use it. To fix this error you can import the offending component, provider, pipe or directive into the app.module file and then if it is a provider add it to the providers array and for a component, pipe or directive add it to both the declarations array and entryComponents array.

因此,在這種情況下,你需要將它添加到兩者的entryComponentsdeclarations陣列:

import { BoxPage } from 'the/path/to/the/file'; 
// ... 

@NgModule({ 
    declarations: [ 
     // ... 
     BoxPage // <- Here! 
    ], 
    imports: [ 
     // ... 
    ], 
    bootstrap: [IonicApp], 
    entryComponents: [ 
     // ... 
     BoxPage // <- and also here! 
    ], 
    providers: [ 
     // ... 
    ] 
}) 
export class AppModule { } 
+1

這工作得很好,但一個問題仍然存在所有新設計的頁面上都沒有後退按鈕,我仍然錯過了一些東西? – OshoParth

+0

嗯,這與所有這些都沒有關係......你能否在這個頁面的代碼上加上另一個問題,讓我看看它? – sebaferreras