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
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.
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.
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.
I see you are missing RouterModule
inside the imports of UIModule
@NgModule({
imports: [
CommonModule,
RouterModule
],
declarations: [LayoutComponent, HeaderComponent, FooterComponent],
exports: [LayoutComponent]
})
export class UiModule { }
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
You are getting the error because you are using the router-outlet component in the UIModule and didn't import the RouterModule inside UIModule.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With