我有以下幾點:角路由未被捕獲的錯誤
我收到一個錯誤說:
:compiler.es5.js:1690 Uncaught Error: Template parse errors:
Can't bind to 'routerLink' since it isn't a known property of 'a'. (" <div class="navbar-header">
<ul class="nav navbar-nav list-inline">
<li class="home"><a [ERROR ->][routerLink]="['/home']">Login</a></li>
<li class="child"><a [routerLink]="['/child']">Child</a>"): ng:///HomeModule/[email protected]:25
Can't bind to 'routerLink' since it isn't a known property of 'a'. ("inline">
<li class="home"><a [routerLink]="['/home']">Login</a></li>
<li class="child"><a [ERROR ->][routerLink]="['/child']">Child</a></li>
<li class="parent"><a [routerLink]="['/parent']">Parent"): ng:///HomeModule/[email protected]:26
Can't bind to 'routerLink' since it isn't a known property of 'a'. ("</li>
<li class="child"><a [routerLink]="['/child']">Child</a></li>
<li class="parent"><a [ERROR ->][routerLink]="['/parent']">Parent</a></li>
</ul>
</div>
但是我在app.modules.ts宣佈它
@NgModule({
declarations: [],
imports: [
RouterModule.forRoot(appRoutes),
BrowserModule,
ChildModule,
ParentModule,
HomeModule
],
providers: [],
bootstrap: [HomeComponent]
})
export class AppModule { }
在我的HomeComponent.html我有標題:
<header id="header">
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<ul class="nav navbar-nav list-inline">
<li class="home"><a [routerLink]="['/home']">Login</a></li>
<li class="child"><a [routerLink]="['/child']">Child</a></li>
<li class="parent"><a [routerLink]="['/parent']">Parent</a></li>
</ul>
</div>
</div>
</nav>
</header>
但它是說它承認屬性。
我已上載的代碼的GitHub:[GitHub的] [2]
------------更新1 -------------- -
我更新CommonModule.ts
import { NgModule } from '@angular/core';
import {RouterModule} from '@angular/router';
@NgModule({
declarations: [],
// you don't need anything here since this module has no templates for Angular to parse!
imports: [RouterModule],
exports: [
RouterModule
]
})
export class CommonModule { }
然後我導入到app.module.ts
@NgModule({
declarations: [],
imports: [
BrowserModule,
ChildModule,
ParentModule,
HomeModule,
CommonModule
],
providers: [],
bootstrap: [HomeComponent]
})
export class AppModule { }
錯誤:
[2]:https://github.com/drewjocham/Routing.gitERROR在
ERROR in /Users/drew/Documents/OutputInput/Sample/node_modules/@angular/common/src/common_module.d.ts (11,15): Cannot find name 'RouterModule'.
ERROR in /Users/drew/Documents/OutputInput/Sample/node_modules/@angular/common/src/common_module.d.ts (13,9): Cannot find name 'RouterModule'.
你可以請加在你聲明HomeComponent模塊? –
是否解決了此問題? –