Angular Guard is not able to access the Angular Service Object

浪尽此生 提交于 2019-12-11 06:37:25

问题


I am trying to access the Angular Service Object (I have set the AuthContext in service) but Angular Guard is giving undefined even though that is well set.

I have login component, which I call first and internally It uses the Angular Auth Service. In the constructor of that service, I ensure that AuthContext is well set. Through the debug, I have seen that object is available with all the required claims.

But then when I access the regular component (which I have guarded through the Auth Guard) CanActivate method in that Guard fails to access the context.

Any idea why? Here is little overview of my code...

I also have tried to use the console log and it looks like Auth Guard called before the service class. But Auth.Guard, I have used authservice in constructor and by virtue of Dependency injection, Service object should get called.. Don't know what's wrong here...

Here is console log

any suggestion?

来源:https://stackoverflow.com/questions/52134624/angular-guard-is-not-able-to-access-the-angular-service-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!