“No provider for AuthGuard!” using CanActivate in Angular 2

后端 未结 12 2075
陌清茗
陌清茗 2021-02-03 20:09

EDIT : Obviously this is outdated, now you provide your guard at the providers array in an NgModule. Watch other answers or official documentation

12条回答
  •  鱼传尺愫
    2021-02-03 20:40

    I encountered this issue when I was following a tutorial. I tried most of the answer here but not getting any success. Then I tried the silly way like putting the AuthGuard before the other services in the provider and it works.

    // app.module.ts
    
     .. 
     providers: [
       AuthGuard,
       UserService,
       ProjectService
      ]
    

提交回复
热议问题