How to hide link by guard angular2

前端 未结 2 2050
我寻月下人不归
我寻月下人不归 2021-02-08 10:45

How to hide admin link in view html. I have to guard :Admin and Manager

Router config :

{
   path: \'manager\',
   component: ManagerComponent,
   canAct         


        
2条回答
  •  爱一瞬间的悲伤
    2021-02-08 11:21

    Also if already answered in a way which might be helpful, I used here another approach. As you already have your canActivate method in the Guard, you could also inject your navigation component with that Guards and you can call these canActivate methods directly:

    In your component which holds the navigation

    constructor(private adminGuard: AdminGuard)
    

    and then in the template

  • User
  • Edit

    This does not work in prod mode in my case (if you use parameters which have to be injected). I just tried to compile it but angular complains about the missing parameters. If you do not use parameters, this works fine, or, if you do not use the parameters in your function - then simply pass

  • User
  • Another thing: If you is variables like the 'adminGuard' above in the template, it must be public - not private.

提交回复
热议问题