Can't bind to 'routerLink' since it isn't a known property

后端 未结 9 850
别那么骄傲
别那么骄傲 2020-12-12 14:16

Recently, I have started playing with angular 2. It\'s awesome so far. So, i have started a demo personal project for the sake of learning using angular-cli. <

相关标签:
9条回答
  • 2020-12-12 14:50

    I totally chose another way for this method.

    app.component.ts

    import { Router } from '@angular/router';
    export class AppComponent {
    
       constructor(
            private router: Router,
        ) {}
    
        routerComment() {
            this.router.navigateByUrl('/marketing/social/comment');
        }
    }
    

    app.component.html

    <button (click)="routerComment()">Router Link </button>
    
    0 讨论(0)
  • 2020-12-12 14:58

    You need to add RouterMoudle into imports sections of the module containing the Header component

    0 讨论(0)
  • 2020-12-12 14:58

    In the current component's module import RouterModule.

    Like:-

    import {RouterModule} from '@angular/router';
    @NgModule({
       declarations:[YourComponents],
       imports:[RouterModule]
    

    ...

    It helped me.

    0 讨论(0)
提交回复
热议问题