[英]ERROR in No NgModule metadata found for 'HomeModule'
I am getting the error mentioned in the title when running the Ionic CLI command ionic cordova run android
. 运行Ionic CLI命令ionic cordova run android
时,出现标题中提到的错误。
What I tried to fix the problem: 我试图解决的问题:
Checked that main.ts
file contains the following code 检查main.ts
文件是否包含以下代码
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err));
Removed node_modules
folder and ran npm install
. 删除了node_modules
文件夹并运行了npm install
。
Reinstalle angular/cli with the commands posted in this answer . 使用此答案中发布的命令重新安装angular / cli。
app.module.ts: app.module.ts:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } 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 { HttpClientModule } from '@angular/common/http';
import { SijaintiService } from '../app/sijainti.service';
import { RouterModule, Routes } from '@angular/router';
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [
BrowserModule,
IonicModule.forRoot(),
AppRoutingModule,
HttpClientModule,
RouterModule.forRoot([
{ path: '', redirectTo: '/home', pathMatch: 'full' },
{ path: 'home', loadChildren: './home/home.module#HomeModule' },
{ path: 'tiedot', loadChildren: './tiedot/tiedot.module#TiedotModule' }
])
],
providers: [
StatusBar,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
SijaintiService
],
bootstrap: [AppComponent]
})
export class AppModule {}
home.module.ts: home.module.ts:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { IonicModule } from '@ionic/angular';
import { FormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { HomePage } from './home.page';
@NgModule({
imports: [
CommonModule,
FormsModule,
IonicModule,
RouterModule.forChild([
{
path: '',
component: HomePage
}
])
],
declarations: [HomePage]
})
export class HomePageModule {}
Change HomeModule to HomePageModule in your route list, because your class name is HomePageModule. 在路由列表中将HomeModule更改为HomePageModule ,因为您的类名称为HomePageModule。
Change this, 改变这个
{ path: 'home', loadChildren: './home/home.module#HomeModule' },
to this, 为此,
{ path: 'home', loadChildren: './home/home.module#HomePageModule' },
You are naming the module as HomePageModule
and the error is HomeModule
not defined. 您将模块命名为HomePageModule
,错误是HomeModule
。 Could be a typo ? 可能是拼写错误吗?
You could either rename the export as 您可以将导出重命名为
export class HomeModule {}
or modify the lazy loaded module as 或将延迟加载的模块修改为
{ path: 'home', loadChildren: './home/home.module#HomePageModule' }, // from HomeModule
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.