No provider for Router?

后端 未结 8 978
情书的邮戳
情书的邮戳 2020-12-01 08:57

Im getting this error:

EXCEPTION: Error in ./AppComponent class AppComponent - inline template:0:0 caused by: No provider for Router!

8条回答
  •  日久生厌
    2020-12-01 09:22

    If you created a separate module (eg. AppRoutingModule) to contain your routing commands you can get this same error:

    Error: StaticInjectorError(AppModule)[RouterLinkWithHref -> Router]: 
    StaticInjectorError(Platform: core)[RouterLinkWithHref -> Router]: 
    NullInjectorError: No provider for Router!
    

    You may have forgotten to import it to the main AppModule as shown here:

    @NgModule({
      imports:      [ BrowserModule, FormsModule, RouterModule, AppRoutingModule ],
      declarations: [ AppComponent, Page1Component, Page2Component ],
      bootstrap:    [ AppComponent ]
    })
    export class AppModule { }
    

提交回复
热议问题