skip to Main Content

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

Answers


  1. 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]

    Login or Signup to reply.
  2. 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 { }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search