首页 > 解决方案 > “路由器插座”不是角度 6 中的已知元素

问题描述

使用 angular-cli 重新安装 angular6 时出现以下错误。

未捕获的错误:模板解析错误:'router-outlet' 不是已知元素: 1. 如果'router-outlet' 是 Angular 组件,则验证它是否是该模块的一部分。

我遵循了本指南:https ://medium.com/@meemo_86/good-article-beeman-490eaf1399a

然后我跟进了对该文章的评论,该文章说使用<router-outlet></router-outlet>而不是<ng-content></ng-content>.

我做了这些更正,然后我阅读了https://angular.io/tutorial/toh-pt5,并按照那里的说明进行操作。

所以现在我有了一个AppRoutingModule,我在 app.module.ts 中导入了那个模块,我还在其中 const 路由并添加RouterModule.forRoot(appRoutes)到导入中。

但我不能让这个错误消失。我究竟做错了什么?当我添加<router-outler></router-outlet>layout.component.htm的 时,应用程序会中断。我也在这里搜索了这个主题并尝试了一些更改,但似乎没有任何效果。

完整的源代码在这里:

https://github.com/ekstremedia/angular6

标签: angularrouter-outlet

解决方案


我看到你RouterModule在 UIModule 的导入中丢失了

@NgModule({
  imports: [
    CommonModule,
    RouterModule
  ],
  declarations: [LayoutComponent, HeaderComponent, FooterComponent],
  exports: [LayoutComponent]
})
export class UiModule { }

推荐阅读