如何修复 Angular 独立组件: Can't bind to 'routerLink' since it isn't a known property of 'a'
问题:
当使用独立组件打开 Angular 应用时,你看到以下错误消息:
angular_router_error.txt
Can't bind to 'routerLink' since it isn't a known property of 'a'解决方案
在发生错误的组件中,添加
import_router_module.ts
import { RouterModule } from '@angular/router';并添加
router_module_import_example.ts
RouterModule,到组件的 imports。示例:
top_bar_component.ts
@Component({
selector: 'app-top-bar',
standalone: true,
imports: [
CommonModule,
RouterModule
],
templateUrl: './top-bar.component.html',
styleUrl: './top-bar.component.sass'
})
export class TopBarComponent {
}Check out similar posts by category:
Angular, Typescript
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow