No provider for Router?

后端 未结 8 967
情书的邮戳
情书的邮戳 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:25

    I had the error of

    No provider for Router

    It happens when you try to navigate in any service.ts

    this.router.navigate(['/home']); like codes in services cause that error.

    You should handle navigating in your components. for example: at login.component

    login().subscribe(
            (res) => this.router.navigate(['/home']),
            (error: any) => this.handleError(error));
    

    Annoying errors happens when we are newbie :)

提交回复
热议问题