Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'router-outlet' is not a known element in angular 6

I get the following error on a fresh install of angular6 using the angular-cli.

Uncaught Error: Template parse errors: 'router-outlet' is not a known element: 1. If 'router-outlet' is an Angular component, then verify that it is part of this module.

I followed this guide: https://medium.com/@meemo_86/good-article-beeman-490eaf1399a

And then I followed up on the comment on that article which says to use <router-outlet></router-outlet> instead of <ng-content></ng-content>.

I do those corrections, then I read up on https://angular.io/tutorial/toh-pt5, and do what is stated there.

So now I have a AppRoutingModule, I import that module in app.module.ts, where I also const the routes and added RouterModule.forRoot(appRoutes) to imports.

But I cannot get this error to go away. What am I doing wrong? When I add <router-outler></router-outlet> in my layout.component.htm, the app breaks. I have also searched this topic here and tried several changes but nothing seems to work.

Full source code is here:

https://github.com/ekstremedia/angular6

like image 306
Terje Nesthus Avatar asked Jul 26 '18 09:07

Terje Nesthus


People also ask

How do you fix router-outlet is not known element?

html:1:1 - error NG8001: 'router-outlet' is not a known element: 1. If 'router-outlet' is an Angular component, then verify that it is part of this module. 2. If 'router-outlet' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.

What is router-outlet in Angular?

The Router-Outlet is a directive that's available from the router library where the Router inserts the component that gets matched based on the current browser's URL. You can add multiple outlets in your Angular application which enables you to implement advanced routing scenarios.

How do I fix NG8001?

Debugging the errorlink Use the element name in the error to find the file(s) where the element is being used. Check that the name and selector are correct. Make sure that the component is correctly imported inside your NgModule or standalone component, by checking its presence in the imports field.


3 Answers

I see you are missing RouterModule inside the imports of UIModule

@NgModule({
  imports: [
    CommonModule,
    RouterModule
  ],
  declarations: [LayoutComponent, HeaderComponent, FooterComponent],
  exports: [LayoutComponent]
})
export class UiModule { }
like image 154
Sajeetharan Avatar answered Oct 10 '22 17:10

Sajeetharan


I met the same problem too. And I already imported the RouterModule inside UIModule, still doesn't work. But after I restart the app, it worked, no more errors.

So, what you should do is: 1. Import the RouterModule inside UIModule; 2. Restart your app

like image 23
李岳芸 Avatar answered Oct 10 '22 17:10

李岳芸


You are getting the error because you are using the router-outlet component in the UIModule and didn't import the RouterModule inside UIModule.

like image 5
SplitterAlex Avatar answered Oct 10 '22 18:10

SplitterAlex