I've been at this problem for a few hours now. I have tried literally everything but I can't get it to work.
The next error keeps ing up:
zone.js:522 Unhandled Promise rejection: Template parse errors:
'router-outlet' is not a known element:
1. If 'router-outlet' is an Angular ponent, 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.schemas' of this ponent to suppress this message.
Here are my files, which I have reduced to the basic needs for routing:
app-routing.module.ts
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { TafelComponent } from '../tafel/tafelponent';
import { MuurtafelComponent } from '../muurtafel/muurtafelponent';
const routes: Routes = [
{ path: 'tafel', ponent: TafelComponent },
{ path: 'muurtafel', ponent: MuurtafelComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './appponent';
import { TafelComponent } from './tafel/tafelponent';
import { MuurtafelComponent } from './muurtafel/muurtafelponent';
import { AppRoutingModule } from './app-routing/app-routing.module';
@NgModule({
imports: [
BrowserModule,
FormsModule,
AppRoutingModule,
HttpModule
],
exports: [AppRoutingModule],
declarations: [
AppComponent,
TafelComponent,
MuurtafelComponent
],
bootstrap: [AppComponent]
})
export class AppModule { }
appponent.html
<router-outlet></router-outlet>
<h1>
{{title}}
</h1>
index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Industial Furniture</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<base href="/">
</head>
<body>
<app-root>Loading...</app-root>
</body>
</html>
Can someone help me with this? Could it be anything outside of the code? (Or is it that I'm overseeing something here?)
I've been at this problem for a few hours now. I have tried literally everything but I can't get it to work.
The next error keeps ing up:
zone.js:522 Unhandled Promise rejection: Template parse errors:
'router-outlet' is not a known element:
1. If 'router-outlet' is an Angular ponent, 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.schemas' of this ponent to suppress this message.
Here are my files, which I have reduced to the basic needs for routing:
app-routing.module.ts
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { TafelComponent } from '../tafel/tafel.ponent';
import { MuurtafelComponent } from '../muurtafel/muurtafel.ponent';
const routes: Routes = [
{ path: 'tafel', ponent: TafelComponent },
{ path: 'muurtafel', ponent: MuurtafelComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.ponent';
import { TafelComponent } from './tafel/tafel.ponent';
import { MuurtafelComponent } from './muurtafel/muurtafel.ponent';
import { AppRoutingModule } from './app-routing/app-routing.module';
@NgModule({
imports: [
BrowserModule,
FormsModule,
AppRoutingModule,
HttpModule
],
exports: [AppRoutingModule],
declarations: [
AppComponent,
TafelComponent,
MuurtafelComponent
],
bootstrap: [AppComponent]
})
export class AppModule { }
app.ponent.html
<router-outlet></router-outlet>
<h1>
{{title}}
</h1>
index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Industial Furniture</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<base href="/">
</head>
<body>
<app-root>Loading...</app-root>
</body>
</html>
Can someone help me with this? Could it be anything outside of the code? (Or is it that I'm overseeing something here?)
Share Improve this question edited Feb 7, 2020 at 4:36 Tony 20.2k7 gold badges41 silver badges62 bronze badges asked Feb 6, 2020 at 21:30 SkiseronySkiserony 291 silver badge2 bronze badges 1-
Maybe you can try to create a new Angular project and try the
router-outlet
there and see if it works. If it does, then its something wrong with your code/project, and then you need to pare the project that is working to the one that isn't and see where the differences are. If it doesn't work, then it's something wrong with the installation or the IDE. – Compiler v2 Commented Feb 6, 2020 at 21:40
3 Answers
Reset to default 3In your app.module.ts
@NgModule({
...,
imports: [
AppRoutingModule
],
exports: [AppRoutingModule], // Remove this line
...
})
You don't need to export here !
I didn't deeply delve into your code, but I got the same error after rename package + ponent name. I also checked all my code, but found nothing, I just tried stop CLI and restart. All piled good and started working. Maybe this will help.
In your app.module.ts remove
exports: [AppRoutingModule],
Also kill the server then run ng serve
again
Another note that I saw you use
HttpModule
instead
HttpClientModule
New version of angular already use HttpClientModule
so try to use lastest version if you can