11

I've just created a new angular project using the Angular CLI and scaffolded a new route and I am getting error as :

'router-outlet' is not a known element

Can anyone help me ?

NARGIS PARWEEN
  • 1,489
  • 3
  • 16
  • 26

4 Answers4

16

Please add

import { RouterModule } from '@angular/router';

in app.module.ts and import it in imports -

imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    RouterModule
],

This worked for me.

isherwood
  • 58,414
  • 16
  • 114
  • 157
Meghana
  • 197
  • 3
6

Here is the solution that worked for me, inspired by gaurav2887 from this page:

import { RouterTestingModule } from '@angular/router/testing';
...    
beforeEach(() => {
        TestBed.configureTestingModule({
            declarations: [ MyComponent ],
            imports: [ RouterTestingModule ]
        });
...
ThCollignon
  • 976
  • 3
  • 14
  • 31
4

You need to first import Routes & RouterModule

import { Routes, RouterModule } from '@angular/router';

Then import it with root Constant and Export

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})

Then Export all the Components you want to implement routing with.

That set...Hope it will work.

Deepak swain
  • 3,380
  • 1
  • 30
  • 26
-1

The following worked!

Using:

"@angular/router": "3.1.2",
Unheilig
  • 16,196
  • 193
  • 68
  • 98
Nick Chlam
  • 17
  • 2