https://github.com/tekvando/ngx-permission
Role based access control for your angular 2 or angular 4 applications
https://github.com/tekvando/ngx-permission
access access-control acl angular angular2 angular4 ng2 ngx ngx-permission permissions rbac roles route
Last synced: 2 months ago
JSON representation
Role based access control for your angular 2 or angular 4 applications
- Host: GitHub
- URL: https://github.com/tekvando/ngx-permission
- Owner: TekVanDo
- License: mit
- Created: 2017-07-29T23:24:58.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-08-12T21:09:41.000Z (almost 8 years ago)
- Last Synced: 2025-02-21T09:13:35.942Z (4 months ago)
- Topics: access, access-control, acl, angular, angular2, angular4, ng2, ngx, ngx-permission, permissions, rbac, roles, route
- Language: TypeScript
- Homepage: https://tekvando.github.io/ngx-permission/docs
- Size: 1.37 MB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ngx permission
[](https://travis-ci.org/TekVanDo/ngx-permission)
[](https://codecov.io/gh/TekVanDo/ngx-permission)
[](http://badge.fury.io/js/ngx-permission)
[](https://david-dm.org/TekVanDo/ngx-permission?type=dev)
[](https://github.com/TekVanDo/ngx-permission/issues)
[](https://github.com/TekVanDo/ngx-permission/stargazers)
[](https://raw.githubusercontent.com/TekVanDo/ngx-permission/master/LICENSE)## Table of contents
- [About](#about)
- [Installation](#installation)
- [Integration with router](#router)
- [Documentation](#documentation)
- [Roadmap](#roadmap)
- [Development](#development)
- [License](#license)## About
Angular 2 or Angular 4 implementation of [angular-permission](https://github.com/Narzerus/angular-permission)
## Installation
Install through npm:
```
npm install --save ngx-permission
```Then include in your apps module:
```typescript
import { NgModule } from '@angular/core';
import { NgxPermissionModule } from 'ngx-permission';@NgModule({
imports: [
NgxPermissionModule
]
})
export class MyModule {}
```Define role and role validation function by RoleStoreService
```typescript
export class AppComponent {
constructor(roleStoreService:RoleStoreService) {
const adminRole: Role = {
name: 'admin',
validationFunction: () => false
};
const userRole: Role = {
name: 'user',
validationFunction: () => true //boolean or Promise
};
roleStoreService.defineRole(adminRole);
roleStoreService.defineRole(userRole);
// or roleStoreService.defineManyRoles([adminRole, userRole])
}
}
```Now you can use onlyForRoles and exceptRoles directives in your components:
```typescript
import { Component } from '@angular/core';@Component({
template: `user can see this
user can't see this`
})
export class MyComponent {}
```## Router
set canActivate property RouterConnector class
```
{
path: 'about',
component: AboutComponent,
data: {
ngxPermissions: {
only: ['user']
}
},
canActivate: [RouterConnector]
},
{
path: 'secret',
component: SectetDataComponent,
data: {
ngxPermissions: {
exept: ['user'],
redirectTo: 'about'
}
},
canActivate: [RouterConnector]
}
```### Usage without a module bundler
```// everything is exported ngxPermission namespace
```
## Documentation
All documentation is auto-generated from the source via [compodoc](https://compodoc.github.io/compodoc/) and can be viewed here:
https://TekVanDo.github.io/ngx-permission/docs/## Roadmap
* implements forRoot and forChild functions
* add support for observables
* implements permissions
* improve documentation
* better tests coverage
* nested roles## Development
### Prepare your environment
* Install [Node.js](http://nodejs.org/) and NPM
* Install local dev dependencies: `npm install` while current directory is this repo### Development server
Run `npm start` to start a development server on port 8000 with auto reload + tests.### Testing
Run `npm test` to run tests once or `npm run test:watch` to continually run tests.### Release
* Bump the version in package.json (once the module hits 1.0 this will become automatic)
```bash
npm run release
```## License
MIT