angular7 中 2 个模块错误的声明
declarations of 2 modules error in angular7
我正在尝试 运行 我的项目,只有一个组件,我将 home 添加到 app.module 但它给我带来了这个错误
错误:未捕获(承诺):错误:类型 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
在 AppModule
中更改为 declarations: [AppComponent],
如果你想在路由中使用主页你可以配置
{
path: 'homepage',
loadChildren: './homepage/homepage.module#HomePageModule'
},
您可以执行以下操作 从主页模块中删除 declarations: [HomePage]
。如果你不是延迟加载
或
您可以将其保留在主页模块中并删除
来自应用程序模块的主页 declarations: [AppComponent,HomePage],
如果你懒加载
或者如果你只想将它模块化
您可以将其保留在主页模块中并删除
从应用程序模块 declarations: [AppComponent,HomePage],
主页将其添加到主页模块中的 exports:[HomePage]
并将主页模块导入 appmodule`
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule,RouterModule],HomePageModule,...
我正在尝试 运行 我的项目,只有一个组件,我将 home 添加到 app.module 但它给我带来了这个错误
错误:未捕获(承诺):错误:类型 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
在 AppModule
declarations: [AppComponent],
如果你想在路由中使用主页你可以配置
{
path: 'homepage',
loadChildren: './homepage/homepage.module#HomePageModule'
},
您可以执行以下操作 从主页模块中删除 declarations: [HomePage]
。如果你不是延迟加载
或
您可以将其保留在主页模块中并删除
来自应用程序模块的主页 declarations: [AppComponent,HomePage],
如果你懒加载
或者如果你只想将它模块化
您可以将其保留在主页模块中并删除
从应用程序模块 declarations: [AppComponent,HomePage],
主页将其添加到主页模块中的 exports:[HomePage]
并将主页模块导入 appmodule`
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule,RouterModule],HomePageModule,...