0

Although I have used a previous stackoverflow solution, I still get the same error. The other problem is that there is no script in Angular 20 that has @NgModule. Here is the code I have:

navbar.html

    <li class="nav-item">
       <a class="nav-link" [routerLink]="['/']" [routerLinkActive]="['active']">Home</a>
    </li>
    <li class="nav-item">
       <a class="nav-link" [routerLink]="['/contact']" [routerLinkActive]="['active']">Contact</a>
    </li>

navbar.ts

    import { Component } from '@angular/core';
    
    @Component({
      selector: 'navbar',
      imports: [],
      templateUrl: './navbar.html',
      styleUrl: './navbar.scss'
    })
    
    export class Navbar {
    
    }

3
  • Related: In standalone mode, how to I import a module in Angular 17? Commented Jun 30 at 5:22
  • 1
    This question is similar to: Can't bind to 'routerLink' since it isn't a known property. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Jun 30 at 7:52
  • This solution is different from DarkBee's suggestion because Angular 20 doesn't have @NgModule, so you have to import RouterModule directly into the component you want to use it in. Karthik S found a similar solution, but it doesn't explicitly state RouterModule, however, it is implied that you can import it the same way as Angular 17. Commented Jul 6 at 1:08

1 Answer 1

0

Since Angular 20 doesn't have a script with @NgModule, you can just import the RouterModule per component like so:

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

@Component({
  selector: 'navbar',
  imports: [RouterModule],
  templateUrl: './navbar.html',
  styleUrl: './navbar.scss'
})

export class Navbar {

}

That fixed the error of "Can't bind to 'routerLink' since it isn't a known property of 'a'"

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.