I'm trying to run my project, there is just one component, I added home to app.module but its ginvg me this error
Error: Uncaught (in promise): Error: Type HomePage is part of the declarations of 2 modules: AppModule and HomePageModule! Please consider moving HomePage to a higher module that imports AppModule and HomePageModule. You can also create a new NgModule that exports and includes HomePage then import that NgModule in AppModule and HomePageModule. Error: Type HomePage is part of the declarations of 2 modules: AppModule and HomePageModule! Please consider moving HomePage to a higher module that imports AppModule and HomePageModule. You can also create a new NgModule that exports and includes HomePage then import that NgModule in AppModule and HomePageModule. here's my app.module
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule, RouteReuseStrategy, Routes } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { HomePage} from './home/home.page';
@NgModule({
declarations: [AppComponent,HomePage],
entryComponents: [],
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule,RouterModule],
providers: [
StatusBar,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
bootstrap: [AppComponent]
})
export class AppModule {}
You should remove HomePage
from declarations
change to declarations: [AppComponent],
in AppModule
If you want to use HomePage in route you can configure
{
path: 'homepage',
loadChildren: './homepage/homepage.module#HomePageModule'
},
You could do the following Remove the declarations: [HomePage]
from the Homepage Module. if you are not lazy loading
or
you could Either keep it there in the homepage module and remove Homepage it from app modules declarations: [AppComponent,HomePage],
if you are lazy loading
or if you want to just modularize it you could Either keep it there in the homepage module and remove Homepage it from app modules declarations: [AppComponent,HomePage],
and add it to exports:[HomePage]
in home page Module and import The homepage module to appmodule`
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule,RouterModule],HomePageModule,...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.