找不到“ HomeModule”的NgModule元数据中的错误

时间:2019-02-03 19:20:19

标签: angular ionic-framework ionic4

运行Ionic CLI命令ionic cordova run android时出现标题中提到的错误。

我试图解决的问题:

检查main.ts文件是否包含以下代码

platformBrowserDynamic().bootstrapModule(AppModule)
  .catch(err => console.log(err));

已删除node_modules文件夹并运行npm install

使用in this answer发布的命令重新安装angular / cli。

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:

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

2 个答案:

答案 0 :(得分:1)

在路由列表中将 HomeModule 更改为 HomePageModule ,因为您的类名是HomePageModule。

更改此内容

 { path: 'home', loadChildren: './home/home.module#HomeModule' },

对此,

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

答案 1 :(得分:0)

您将模块命名为HomePageModule,错误是HomeModule尚未定义。可能是拼写错误吗?

您可以将导出重命名为

export class HomeModule {}

或将延迟加载的模块修改为

{ path: 'home', loadChildren: './home/home.module#HomePageModule' }, // from HomeModule