0

I work on angular 11 I face error when build angular app

    ERROR in src/app/Employee-list/employee-list.component.html:22:45 - error NG8002: Can't bind to 
'routerLink' since it isn't a known property of 'a'.
<a class="nav-link text-dark" [routerLink]="['/employee-list']">Staff List</a>

and below is package json file

    "@angular/animations": "^11.2.14",
    "@angular/cdk": "^12.1.3",
    "@angular/common": "^11.0.0",
    "@angular/compiler": "^11.0.0",
    "@angular/core": "^11.0.0",
    "@angular/forms": "^11.0.0",
    "@angular/material": "^11.2.13",
    "@angular/router": "^11.2.14",
    "@angular/cli": "^11.0.0",
    "@angular/compiler-cli": "^11.0.0"

on application module I do as below :

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


@NgModule({
 
  imports: [
    RouterModule

so How to solve issue ?

sample of app modules and component employee list exist as blow

https://stackblitz.com/edit/angular-uffug5?file=src%2Fapp%2FEmployee-list%2Femployee-list.component.ts

image for issue

issue router link

ahmed barbary
  • 628
  • 6
  • 21
  • 1
    This is a pretty common issue, do any of the answers in the following threads help you? [Can't bind to 'routerLink' since it isn't a known property](/questions/42035387/cant-bind-to-routerlink-since-it-isnt-a-known-property), [Can't bind to 'routerLink' since it isn't a known property of 'a'](https://stackoverflow.com/questions/39734632/cant-bind-to-routerlink-since-it-isnt-a-known-property-of-a), [Template parse errors: Can't bind to 'routerLink' since it isn't a known property of 'a'](/questions/41268477/template-parse-errors-cant-bind-to-routerlink-since-it-isnt-a-known-propert) – D M Jul 30 '21 at 13:11
  • thank you for reply i already add RouterModule on import section of app module so please can you help me i try more for this issue – ahmed barbary Jul 30 '21 at 13:16
  • Can you please post your entire app.module as well as your employeeList HTML file and employeeList component file? – cklimowski Jul 30 '21 at 13:17
  • this is entirly app.module and employeecomponent https://stackblitz.com/edit/angular-uffug5?file=src%2Fapp%2FEmployee-list%2Femployee-list.component.ts – ahmed barbary Jul 30 '21 at 13:28
  • i post it entirly app.module and component employeelist are you goted – ahmed barbary Jul 30 '21 at 13:40
  • can any one help me – ahmed barbary Jul 30 '21 at 13:57
  • can any one help me i really search more on internet for solve to this issue – ahmed barbary Jul 30 '21 at 15:03
  • i spent more time to solve issue can any one help me tell me what i do are this issue from angular version or what – ahmed barbary Jul 30 '21 at 15:18

1 Answers1

2

You either have to change [routerLink]="['/employee-list']" to routerLink="/employee-list"

or you have to set a property in your component like this and change routerlink:

export class yourComponent {

    public yourRouterLink= "/employee-list"; // Here is your employee-list
}

<a class="nav-link text-dark" [routerLink]="yourRouterLink">Staff List</a>
Dgotin
  • 38
  • 8