Is it possible to switch component in angular like switching templates based on user roles?:
@Component({
selector: 'app-order-select',
template: `
<div *ngIf="storage.getUserRole() == 'admin'">{require('./order-select.component.html')} </div>
<div *ngIf="storage.getUserRole() == 'legal'"> {require('./order-select.component-legal.html')} </div>`,
styleUrls: ['./order-select.component.css']
})
export class OrderSelectComponent implements OnInit {
}
My app route:
{
path: 'orders/select',
component: OrderSelectComponent,
canActivate: [AuthGuard]
},
You can use:
<div id="roleDependantContent">
<app-component-admin *ng-if="storage.getUserRole() == 'admin'"/>
<app-component-user *ng-if="storage.getUserRole() == 'user'"/>
</div>
It will only load the component fitting your user's role.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments