htmlangularrouterlink

How can I solve this error usging routerLink in angular 17.2


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


Solution

  • 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 { }