I'm currently utilizing ngx-permissions (https://www.npmjs.com/package/ngx-permissions) within my project to effectively manage user permissions within my application.
While it seems straightforward to authorize roles in the HTML section, permissions seem to be a bit trickier...
Our desired setup is as follows:
HTML:
<div *ngxPermissionsOnly="['voirResources']">1232465</div>
Typescript:
ngOnInit() {
const roleMetier: Role = new Role();
roleMetier.nom = 'ADMIN';
roleMetier.permissions = ['voirHighlightCard', 'voirResources', 'voirTout', 'voirNextSteps'];
this.rolesService.addRole(roleMetier.nom, roleMetier.permissions);
this.permissionsService.loadPermissions(['ADMIN']);
}
As shown above, I have defined the Admin role along with specific permissions. Subsequently, I load these permissions for current users assigned as admins.
In the HTML code snippet, I include *ngxPermissions="['voirResources']" to restrict the visibility of div content solely to users with the "voirResources" permission.
For a live demo, check out the code on StackBlitz here: https://stackblitz.com/edit/angular-poc-ngx-permissions
I have a couple of inquiries:
- Is it achievable using ngx-permissions?
- If not supported by ngx-permissions, do you know of any alternative npm packages that could serve the purpose? I prefer avoiding reinventing the wheel if there's already a reliable solution available ^^
Thank you in advance for your insights!