Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.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_Typescript_Routing_Angular8 - Fatal编程技术网

Angular 角8模块布线

Angular 角8模块布线,angular,typescript,routing,angular8,Angular,Typescript,Routing,Angular8,在我在shop.module.ts和shop.routing.ts中添加另一个组件声明之前,angular 8应用程序是正常的 Myapp.routing.ts export const AppRoutes: Routes = [ { path: '', redirectTo: 'shop', pathMatch: 'full', }, { path: '', component: FrontendPanelLayoutComponent,

在我在shop.module.ts和shop.routing.ts中添加另一个组件声明之前,angular 8应用程序是正常的

Myapp.routing.ts

export const AppRoutes: Routes = [
  {
    path: '',
    redirectTo: 'shop',
    pathMatch: 'full',
  },
  {
    path: '',
    component: FrontendPanelLayoutComponent,
    children: [
      {
        path: 'shop',
        loadChildren: './shop/shop.module#ShopModule'
      }

    ]
  }

];
@NgModule({
  imports: [
    CommonModule,
    GlobalModule,
    SlickModule.forRoot(),
    NouisliderModule,
    AgmCoreModule.forRoot({apiKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'}),
    RouterModule.forChild(ShopRoutes),
  ],
  declarations: [
    ShopListingComponent,
    ShopDetailComponent  //I newly put this one.
  ],
  providers: [
    ShopService
  ]
})
export class ShopModule { }
Myshop.module.ts

export const AppRoutes: Routes = [
  {
    path: '',
    redirectTo: 'shop',
    pathMatch: 'full',
  },
  {
    path: '',
    component: FrontendPanelLayoutComponent,
    children: [
      {
        path: 'shop',
        loadChildren: './shop/shop.module#ShopModule'
      }

    ]
  }

];
@NgModule({
  imports: [
    CommonModule,
    GlobalModule,
    SlickModule.forRoot(),
    NouisliderModule,
    AgmCoreModule.forRoot({apiKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'}),
    RouterModule.forChild(ShopRoutes),
  ],
  declarations: [
    ShopListingComponent,
    ShopDetailComponent  //I newly put this one.
  ],
  providers: [
    ShopService
  ]
})
export class ShopModule { }
我的
shop.routing.ts

export const ShopRoutes: Routes = [
  {
    path: '',
    component: ShopListingComponent
  },
  //I newly put this one.
  {
    path: 'shop/detail',
    component: ShopDetailComponent
  }
];

当我从shop.module.tsshop.routing.ts中删除ShopDetailComponent时,我的应用程序完全正常。当我再次放入ShopDetailComponent时,应用程序将以空白页面运行,不会出现错误。我的路由声明中有什么错误吗?

您应该使用标准的延迟加载方法。 对ShopDetailComponentShopListingComponent使用单独的模块,也可以使用单独的路由模块。最后,在LayoutModule中使用它们

顺便说一句,您当前问题的解决方案: 在shop.module.ts文件中使用FormsModule,如

import { FormsModule }   from '@angular/forms'; //-------- (new line)  
 @NgModule({
      imports: [
        CommonModule,
        GlobalModule,
        SlickModule.forRoot(),
        NouisliderModule,
        AgmCoreModule.forRoot({apiKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'}),
        RouterModule.forChild(ShopRoutes),
        FormsModule   //-------------Add this FormsModule (new line)
      ],
      declarations: [
        ShopListingComponent,
        ShopDetailComponent  //I newly put this one.
      ],
      providers: [
        ShopService
      ]
    })
    export class ShopModule { }
如果问题仍然存在,请务必告诉我。我们可能需要解决其他各种原因,但希望这次更新能解决您的问题


注意:即使浏览器页面为空,您仍然可以在控制台中看到错误

将路径:'shop/detail'更改为路径:'detail',然后重试。前缀
shop
已存在于
app.routing.ts
中-您无需在
shop.routing.t