error NG8002: Can't bind to 'routerLink' since it isn't a known property of 'a'

Asked on May 26, 2023
In my Angular standalone application, I have a route.
<a [routerLink]="['/person-detail', p.id]">View Detail</a>
My component is
@Component({
selector: 'app-person',
standalone: true,
imports: [
CommonModule
],
template: `
<div *ngFor="let p of persons">
<p>{{p.name}} | <a [routerLink]="['/person-detail', p.id]">View Detail</a> </p>
</div>
`
})
export class PersonComponent {
@Input('allPersons') persons?: Person[];
}
Error is :
Error: src/person.component.html:2:20 - error NG8002: Can't bind to 'routerLink' since it isn't a known property of 'a'.
<p>{{p.name}} <a [routerLink]="['/person-detail', p.id]">View Detail</a> </p>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/person.component.ts:
templateUrl: 'person.component.html',
~~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component PersonComponent.

Replied on May 26, 2023
You are missing RouterModule.
Try
imports: [
CommonModule,
RouterModule,
]