Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manage menu based on user roles/permissions in angular

I have started a new angular project, In my application have 3 types of users (admin, customer, and company). How can restrict customers from access admin users menus?

like image 286
byteC0de Avatar asked Mar 24 '17 10:03

byteC0de


1 Answers

You can use ngx-permissions library. It support lazy loading, isolated lazy loading, then else syntax. Load library

@NgModule({

 imports: [

 NgxPermissionsModule.forRoot()
],
providers: [],
bootstrap: [AppComponent]
})

Load roles

this.ngxRolesService.addRole('GUEST', () => {
  return true;
}); 

Secure root

const appRoutes: Routes = [
{ path: 'home',
    component: HomeComponent,
    canActivate: [NgxPermissionsGuard],
    data: {
      permissions: {
        only: 'GUEST'
      }
    }
  },
];

Detailed documentation you can find on WIKI page

like image 154
alexKhymenko Avatar answered Nov 15 '22 07:11

alexKhymenko