No provider for ChildrenOutletContexts (injectionError)

To solve this problem change this line:

imports: [RouterModule.forChild(routes)],

to:

imports: [RouterModule.forRoot(routes)],

The error is caused because RouterModule.forChild() generates a module that contains the necessary directives and routes but doesn't include the routing service. That is what RouterModule.forRoot is for: it generates a module that contains the necessary directives, routes, and the routing service.

More information in Angular docs: Angular - Router Module.


imports: [RouterModule.forRoot(routes)]

Change this line in RoutingModuleclass


This is usually happen to me when I didn't import the correct routing module.

For e.g: Inside AppModule I imported RouterModule from '@angular/router' by mistake instead of AppRoutingModule from './app-routing.module'

When i'm working with the Angular CLI I trust the compiler so I double check my self and in most cases it was my bad so when it comes to generating routing files along with the module i'm positive that Angular team are doing it good

Tags:

Angular