简体   繁体   English

Angular2如果我想将某些组件限制为某些用户,应该使用什么概念。

[英]Angular2 What concept should I be using if I want to restrict some component to certain users.

This is just question to ask what concept of angular2 should I be using coz once I know what concepts to use, I could study them . 这只是一个问题,问我一旦知道要使用什么概念就应该使用coz的哪个概念。

So I have five different user types : admin, guest, teacher, student, parent. 因此,我有五种不同的用户类型:管理员,来宾,老师,学生,父母。

I have many components and few of them are restricted to parent, parent, and admin; 我有很多组件,其中只有少数组件仅限于parent,parent和admin。 Some others are open to all; 其他一些则向所有人开放。 some are only for teacher .. etc. 有些只为老师..等等

Which concept should I be using? 我应该使用哪个概念? ngSwitch/Authguard..? ngSwitch / Authguard ..?

I appreciate your help in advance! 感谢您的帮助!

Guards are specially implemented for such kind of usage. 专门针对此类使用实施了防护措施。 Have a look at the blog https://blog.thoughtram.io/angular/2016/07/18/guards-in-angular-2.html This are the 4 kinds of Guards. 看一下博客https://blog.thoughtram.io/angular/2016/07/18/guards-in-angular-2.html这是四种卫兵。

CanActivate - Decides if a route can be activated CanActivate-确定是否可以激活路由

CanActivateChild - Decides if children routes of a route can be activated CanActivateChild-决定是否可以激活一条路线的子路线

CanDeactivate - Decides if a route can be deactivated CanDeactivate-确定是否可以停用路线

CanLoad - Decides if a module can be loaded lazily CanLoad-决定是否可以延迟加载模块

Practical Example : http://www.sparkbit.pl/angular-2-route-guards-real-life-example/ 实际示例: http : //www.sparkbit.pl/angular-2-route-guards-real-life-example/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM