. Advertisement .
..3..
. Advertisement .
..4..
Hi guys, urgent situation!!!!! I’ve been quite interested in angular-cli lately, however when starting a personal demo project I’m having trouble with the following error: can’t bind to ‘routerlink’ since it isn’t a known property of ‘ a’ When I try to navigate to any routes from the header (which is the router’s origin), I receive the following warning messages:
app.component.html
<app-header></app-header> // Trying to navigate from this component
<router-outlet></router-outlet>
<app-footer></app-footer>
<a [routerLink]="['/signin']">Sign in</a>
Update
1- My package.json
is using the stable @angular/router 3.3.1
version.
2- In my chief app
module, I have brought in the routing-module
.
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 { AlertModule } from 'ng2-bootstrap';
import { LayoutModule } from './layout/layout.module';
import { UsersModule } from './users/users.module';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { PageNotFoundComponent } from './shared/components/not-found.component';
@NgModule({
declarations: [
AppComponent,
PageNotFoundComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
AlertModule.forRoot(),
LayoutModule,
UsersModule,
AppRoutingModule --> This is the routing module.
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
app-routing.module.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { SigninComponent } from './users/signin/signin.component';
import { PageNotFoundComponent } from './shared/components/not-found.component';
const routes: Routes = [
{ path: '**', component: PageNotFoundComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule {}
Then I try to access authorization from a UsersModule
user-routing.module.ts
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { SigninComponent } from './signin/signin.component';
const usersRoutes: Routes = [
{ path: 'signin', component: SigninComponent }
];
@NgModule({
imports: [
RouterModule.forChild(usersRoutes)
],
exports: [
RouterModule
]
})
export class UsersRoutingModule { }
Because I have no concept of router module so when navigating layout module an error occurred
Layout.module.ts
import { NgModule } from '@angular/core';
import { HeaderComponent } from './header/header.component';
import { FooterComponent } from './footer/footer.component';
@NgModule({
declarations: [HeaderComponent, FooterComponent],
exports: [HeaderComponent, FooterComponent]
})
export class LayoutModule{}
I have read many documents but can’t find a way to fix this error. If anyone knows please just help me. Thanks a lot!!!!
The cause:
After studying your post, I found out you should join
RouterModule
toimports
of every@NgModule()
where any component or directive from (in this instance) is used by componentsrouterLink
and<router-outlet>
.Solution:
declarations: []
is able to make elements, directives, and streams visible within the present module.exports: []
allows importing modules to access elements, instructions, and streams. Only the module can see what is put todeclarations
. They become known as a result ofexports
Hope my suggestion will help you to fix this error. Good luck!!