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

后端 未结 9 886
别那么骄傲
别那么骄傲 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:47

    You are missing either the inclusion of the route package, or including the router module in your main app module.

    Make sure your package.json has this:

    "@angular/router": "^3.3.1"
    

    Then in your app.module import the router and configure the routes:

    import { RouterModule } from '@angular/router';
    
    imports: [
            RouterModule.forRoot([
                {path: '', component: DashboardComponent},
                {path: 'dashboard', component: DashboardComponent}
            ])
        ],
    

    Update:

    Move the AppRoutingModule to be first in the imports:

    imports: [
        AppRoutingModule.
        BrowserModule,
        FormsModule,
        HttpModule,
        AlertModule.forRoot(), // What is this?
        LayoutModule,
        UsersModule
      ],
    

提交回复
热议问题