0

I have added the Page(HomePage) that has a component in it in entryComponents but still getting a error as "Error: Uncaught (in promise): Error: Component HomePage is not part of any NgModule or the module has not been imported into your module."

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 {}

1 답변


0

You need to also include HomePage in the declarations array of ngModule. All app components, directives, etc need to do in the declarations array. A good detailed explanation is available here: https://www.joshmorony.com/an-introduction-to-ngmodule-for-ionic-2/


  • Hey, thanks for helping me out but i have tried that one too. It seems to occur only in lazy loading for instance if i declare and do entryComponent in app.module.ts everything seems to be running fine. - sliceh
  • Not a problem. If I'm understanding what you're saying correctly that is expected behavior. Every component your app uses needs to be in declarations. Any component that's going to be used immediately when the app loads (like HomePage appears to be in this case) must also be in entryComponents. Also make sure you're importing the component into ngModule. - amuramoto
  • Yea but it doesn't seem to work if i do it as individual modules. If i declare n use it in app.module.ts then what is the use of lazy loading in this. - sliceh

Related

Latest