Guards on Ionic 3 components

Viewed 1334

in my Ionic 3 app I need to implement a sort of user roles check inside the specific component.

I saw that NavController implements the Angular Guards system but it seems to apply only into a view (or page) navigation scenario.

My scenario instead is made of a page (Dashboard) which contains several components and each component could be displayed depending on the specific user role.

Could you help me finding the best solution in terms of design and best practise?

Thank you so much

1 Answers

What you could do is create a custom directive which is placed on the component you wish to control. Something like:-

<my-component [custom-role-directive]="admin"></my-component>

The custom-role-directive checks the users role and displays or hides accordingly.

Related