2017-05-07 38 views
0

我添加了在entryComponents中有一個組件的頁面(HomePage),但仍然收到一個錯誤:「Error:Uncaught(in promise) :錯誤:組件主頁不是任何NgModule的一部分或該模塊尚未導入到您的模塊。「導航到組件不工作在Ionic Framework中的頁面:3.0.1

Code Block-- 
login.module.ts---- 

@NgModule({ 
    declarations: [ 
    LoginPage, 
    ], 
    imports: [ 
    IonicPageModule.forChild(LoginPage), 
    ], 
    exports: [ 
    LoginPage 
    ], 
    entryComponents:[HomePage]// Added here 
}) 
export class LoginModule {} 
----- 
login.ts---------------- 
@IonicPage() 
@Component({ 
    selector: 'page-login', 
    templateUrl: 'login.html' 
}) 
export class LoginPage { 
createUserId(){ 
    this.myProvider.createUserId(this.value,data=>{ 
    if(data=="success") 
    { 
     this.check_response="UserID created" 
     this.navCtrl.push(HomePage)//-----Getting an error here 
    } 
    else 
    this.check_response="Failure" 
    }) 
    //console.log("submit") 

} 
} 

homepage.module.ts----------- 
@NgModule({ 
    declarations: [ 
    HomePage 

    ], 
    imports: [ 
    IonicPageModule.forChild(HomePage), 
    AddExpenseModule 
    ], 
    exports: [ 
    HomePage 
    ] 
}) 
export class HomePageModule {} 

回答

0

您還需要在ngModule的聲明數組中包含HomePage。所有的應用程序組件,指令等都需要在聲明數組中做。一個很好的詳細解釋可以在這裏找到:https://www.joshmorony.com/an-introduction-to-ngmodule-for-ionic-2/

+0

嘿,謝謝你幫助我,但我也試過了。它似乎只發生在延遲加載實例如果我聲明和做app.module.ts中的entryComponent似乎一切正常運行。 – sliceh

+0

沒問題。如果我理解你說的正確,那是預期的行爲。您的應用使用的每個組件都需要聲明。在應用程序加載時將立即使用的任何組件(如HomePage似乎在這種情況下)也必須位於entryComponents中。還要確保你將組件導入ngModule。 – amuramoto

+0

是的,但它似乎並沒有工作,如果我做它作爲單獨的模塊。如果我聲明n在app.module.ts中使用它,那麼在此使用什麼是延遲加載。 – sliceh