How can I solve this error usging routerLink in angular 17.2

57 views Asked by At

I'm trying to create an small app but in this moment I'm having this error with the routerLink by console. PD I'm new to angular

✘ [ERROR] NG8002: Can't bind to 'routerLink' since it isn't a known property of 'a'.

and this is the html code:

<a [routerLink]="['/gastos', expense.id, 'Edit']">
    <i class="ri-edit-box-line"></i>
</a>

What do you think is my mistake?

The only configuration files I can modify are: app.config.ts app.routes.ts

2

There are 2 answers

0
Daniel Gimenez On BEST ANSWER

If you're using standalone components then just import RouterLink and it should work.

@Component({
  selector: 'app-my-component',
  standalone: true,
  imports: [ CommonModule, RouterLink ],
  template: `
<a [routerLink]="['/gastos', expense.id, 'Edit']">
    <i class="ri-edit-box-line"></i>
</a>
`
})
export class MyComponentComponent { }
0
Ahsin Siddique On

please make sure you have @angular/router": "^17.3.0 in your package.json file and import RouterModule in app.module if you have appRoutingModule then import it in imports: [appRoutingModule]