繁体   English   中英

angular7中的2个模块的声明错误

[英]declarations of 2 modules error in angular7

我正在尝试运行我的项目,只有一个组件,我添加到app.module的主页,但它ginvg我这个错误

错误:未捕获(在承诺中):错误:类型HomePage是2个模块的声明的一部分:AppModule和HomePageModule! 请考虑将HomePage移动到导入AppModule和HomePageModule的更高模块。 您还可以创建一个新的NgModule导出并包含HomePage,然后在AppModule和HomePageModule中导入该NgModule。 错误:类型HomePage是2个模块的声明的一部分:AppModule和HomePageModule! 请考虑将HomePage移动到导入AppModule和HomePageModule的更高模块。 您还可以创建一个新的NgModule导出并包含HomePage,然后在AppModule和HomePageModule中导入该NgModule。 这是我的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 {}

您应该从declarations删除HomePage

更改为declarations: [AppComponent],AppModule

如果要在路由中使用HomePage,可以进行配置

{    
      path: 'homepage',
      loadChildren: './homepage/homepage.module#HomePageModule'
 },

您可以执行以下操作从主页模块中删除declarations: [HomePage] 如果你不是懒加载

要么

您可以在主页模块中保留它并从应用程序模块declarations: [AppComponent,HomePage],删除主页declarations: [AppComponent,HomePage],如果您是延迟加载

或者如果你想模块化你可以将它保存在主页模块中并从app模块declarations: [AppComponent,HomePage],删除它declarations: [AppComponent,HomePage],并将其添加到exports:[HomePage]中的exports:[HomePage]模块并导入主页模块到appmodule`

imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule,RouterModule],HomePageModule,...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM