How to hide admin link in view html. I have to guard :Admin and Manager
Router config :
{
path: \'manager\',
component: ManagerComponent,
canAct
In my opinion this has nothing to do with the router itself.
Your Guards may call another service which has the information about which kind of user is logged in: Admin or Manager.
You should create a service that knows the type of the user. Then inject this service with Dependency Injection into your component where you have the routerLink
.
There you can ask the service and toggle the link with *ngIf
:
-
User
So the service provides a function that gives you the user which is currently logged in and the isAdmin()
-function of the user returns true
or false
. If the user is admin then the will be shown, otherwise it will be hidden.
This is just an example but I hope you get the point. It has more to do with basic functionality of Angular 2 rather than the router of Angular 2. More information about *ngIf
can be found here.