Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 8-应用程序启动时未发现模块_Angular - Fatal编程技术网

Angular 8-应用程序启动时未发现模块

Angular 8-应用程序启动时未发现模块,angular,Angular,我是Angular的新手,在我的项目中发现模块时遇到了一些问题。启动应用程序时,我总是会遇到以下错误: 错误:未捕获(承诺中):错误:找不到模块“”/home/home.module' 当应用程序运行(重新编译)时,文件保存在VsCode中时,错误消失。但在第一次发射时,它又回来了。如果能帮我确定这个问题,我将不胜感激 loadChildren:'./home/home.module#HomeModule' 在我的应用程序中,我有以下结构(这里不包括所有内容) 这是我的app-routing.m

我是Angular的新手,在我的项目中发现模块时遇到了一些问题。启动应用程序时,我总是会遇到以下错误:

错误:未捕获(承诺中):错误:找不到模块“”/home/home.module'

当应用程序运行(重新编译)时,文件保存在VsCode中时,错误消失。但在第一次发射时,它又回来了。如果能帮我确定这个问题,我将不胜感激

loadChildren:'./home/home.module#HomeModule'

在我的应用程序中,我有以下结构(这里不包括所有内容)

这是我的app-routing.module.ts:

import { Routes, RouterModule, PreloadAllModules } from '@angular/router';

import { SidebarComponent } from './shared';
import { ContactComponent } from './contact/contact.component';
import { AboutComponent } from './about/about.component';


const routes: Routes = [
  { 
    path: '',
    component: SidebarComponent,
    outlet: 'sidebar'
  },
  {
    path: 'part',
    loadChildren: './part/part.module#PartModule'
  },
  {
    path: 'home',
    loadChildren: './home/home.module#HomeModule'
  },
  {
    path: 'contact',
    component: ContactComponent
  },
  {
    path: 'about',
    component: AboutComponent
  },
  {
    path: '',
    redirectTo: '/home',
    pathMatch:'full'
  }
];

@NgModule({
  imports: [RouterModule.forRoot(routes, {preloadingStrategy: PreloadAllModules})],
  exports: [RouterModule]
})
export class AppRoutingModule { }
和主路由模块:

import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from './home.component';

const routes: Routes = [
  {
    path: '',
    component: HomeComponent
  }

];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})
export class HomeRoutingModule {}

1。如果您回头看,您将能够看到如何使用
loadChildren
加载模块的示例

举个简单的例子:

const routes: Routes = [
    {
      path: 'home',
      loadChildren: () => import('./home/home.module').then(m => m.HomeModule)
    }
 ];
请注意
。然后(m=>m.HomeModule)
,这是加载它所必需的。 这也称为延迟加载


2。我不建议重新定义一个常量路由,它应该保留在
app.module.ts
文件中。

为什么要导出RouterModule?
const routes: Routes = [
    {
      path: 'home',
      loadChildren: () => import('./home/home.module').then(m => m.HomeModule)
    }
 ];