为什么6号角负重儿童无法正常工作?

时间:2018-12-06 03:04:16

标签: angular angular6 lazy-loading angular6-json-schema-form

我对angular并不陌生,因此我正在通过MaximilianSchwarzmüller的Udemy视频课程“ Angular6 The Complete Guide”学习。我几乎快要完成本课程,但是在“了解角度模块和优化应用程序”单元下的“向配方模块添加延迟加载”一章中,我坚持延迟加载。在此,讲师将整个食谱模块及其路由模块分离出来。我尝试对购物模块执行相同的操作,该模块在应用程序根级别具有路由模块-app-routing.module.ts

1)app-routing.module.ts代码

  import { NgModule } from '@angular/core';
  import { Routes, RouterModule } from '@angular/router';
  import { ShoppingListComponent } from './shopping-list/shopping-list.component';
  import { HomeComponent } from './home/home.component';

  const appRoutes: Routes = [
    { path: '', component: HomeComponent },
    { path: 'recipes', loadChildren: './recipes/recipes.module#RecipesModule'},
    { path: 'shopping-list', loadChildren: './shopping-list/shopping-list.module#ShoppingListModule'}
  //  { path: 'shopping-list', component: ShoppingListComponent }
  ];
  @NgModule({
  imports: [RouterModule.forRoot(appRoutes)],
  exports: [RouterModule]
  })
  export class AppRoutingModule {

  }

2)app.module.ts代码

      import { BrowserModule } from '@angular/platform-browser';
  import { NgModule } from '@angular/core';

  // added below two
  import { HttpModule } from '@angular/http';
  import { AppComponent } from './app.component';
  // added header component
  // import { HeaderComponent } from './header/header.component';
  import { HeaderComponent } from './header/header.component';
  import { ShoppingListService } from './shopping-list/shopping-list.service';
  import { AppRoutingModule } from './app-routing.module';
  import { RecipeService } from './recipes/recipe.service';
  import { DataStorageService } from './shared/data-storage.service';
  import { AuthService } from './auth/auth.service';
  import { AuthGuard } from './auth/auth-guard.service';
  import { SharedModule } from './shared/shared.module';
  // import { ShoppingListModule } from './shopping-list/shopping-list.module';
  import { AuthModule } from './auth/auth.module';
  import { HomeComponent } from './home/home.component';


  @NgModule({
    declarations: [
      AppComponent,
      // add header comp
      HeaderComponent,
      HomeComponent
        ],
    imports: [
      BrowserModule,
      // add Forms and HTTP module
      // FormsModule,
      HttpModule,
      AppRoutingModule,
      SharedModule,
      // ShoppingListModule,
      AuthModule
    ],
    providers: [ShoppingListService, RecipeService, DataStorageService, AuthService, AuthGuard],
    bootstrap: [AppComponent]
  })
  export class AppModule { }

那么,即使根本没有错误,这行代码为什么也不起作用?

{ path: 'shopping-list', loadChildren: './shopping-list/shopping-list.module#ShoppingListModule'}

我附加了我的项目文件结构图像PROJECT FILE STRUCTURE

1 个答案:

答案 0 :(得分:1)

因为您没有购物清单路由模块