Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
¿Hay alguna forma estándar de archivo de acceso basado en roles en angular?

He desarrollado proyectos de acceso a 4 roles en angular. El tablero tiene diferentes páginas de contenido. Cada vez que iniciaba sesión en el portal, inicialmente se llamaba página de panel.

El contenido de este tablero se mostrará según la función del usuario registrado. He usado ngSwitch . Cualquiera conoce una implementación de forma diferente en lugar de usar ngSwitch . Comparta amablemente su respuesta. Está funcionando pero quiero una solución diferente

He explicado lo que hice,

4 roles definidos

SuperAdmin, Admin, AdminUser, Usuario

He creado 4 archivos de componentes. siga este archivo de código component.ts

 export class DashboardComponent implements OnInit { userRole: string; constructor(private authService: AuthService) { this.userRole = this.authService.userRole(); }

archivo HTML:

 <div [ngSwitch]="userRole"> <app-header-component title="Dashboard" *ngSwitchCase="'SuperAdmin'"> </app-header-component> <app-system-integrator-dashboard *ngSwitchCase="'Admin'"> </app-system-integrator-dashboard> <app-organization-admin-dashboard *ngSwitchCase="'AdminUser'"> </app-organization-admin-dashboard> <app-organization-user-dashboard *ngSwitchCase="'User'"> </app-organization-user-dashboard> </div>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

crear directiva como

 /* Usage : *roleIsOneOf="[userType.ADMIN, userType.ANALYST, userType.SUPER_ANALYST]" */ @Directive({ selector: '[roleIsOneOf]', }) export class RoleIsOneOfDirective { constructor(private authService: AuthService, private templateRef: TemplateRef<any>, private viewContainer: ViewContainerRef) { } @Input() set roleIsOneOf(allowedRoles: Role[]) { const userRole: Role = this.authService.userRole(); if (allowedRoles.includes(userRole)) { this.viewContainer.createEmbeddedView(this.templateRef); } else { this.viewContainer.clear(); } } }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!