如何解决错误 NG8002:无法绑定到 'routerLink',因为它不是 'a' 的已知 属性。
How to solve error NG8002: Can't bind to 'routerLink' since it isn't a known property of 'a'.?
我在 angular 11 上工作 我在构建 angular 应用程序时遇到错误
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>
以下是包json文件
"@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"
在应用程序模块上我做了如下操作:
import { RouterModule } from '@angular/router';
@NgModule({
imports: [
RouterModule
所以如何解决问题?
应用程序模块和组件员工列表示例如下所示
https://stackblitz.com/edit/angular-uffug5?file=src%2Fapp%2FEmployee-list%2Femployee-list.component.ts
问题图片
您要么必须将 [routerLink]="['/employee-list']"
更改为 routerLink="/employee-list"
或者你必须像这样在你的组件中设置一个 属性 并更改 routerlink:
export class yourComponent {
public yourRouterLink= "/employee-list"; // Here is your employee-list
}
<a class="nav-link text-dark" [routerLink]="yourRouterLink">Staff List</a>
我在 angular 11 上工作 我在构建 angular 应用程序时遇到错误
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>
以下是包json文件
"@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"
在应用程序模块上我做了如下操作:
import { RouterModule } from '@angular/router';
@NgModule({
imports: [
RouterModule
所以如何解决问题?
应用程序模块和组件员工列表示例如下所示
https://stackblitz.com/edit/angular-uffug5?file=src%2Fapp%2FEmployee-list%2Femployee-list.component.ts
问题图片
您要么必须将 [routerLink]="['/employee-list']"
更改为 routerLink="/employee-list"
或者你必须像这样在你的组件中设置一个 属性 并更改 routerlink:
export class yourComponent {
public yourRouterLink= "/employee-list"; // Here is your employee-list
}
<a class="nav-link text-dark" [routerLink]="yourRouterLink">Staff List</a>