ngx-permission

[![Build Status](https://travis-ci.org/TekVanDo/ngx-permission.svg?branch=master)](https://travis-ci.org/TekVanDo/ngx-permission) [![codecov](https://codecov.io/gh/TekVanDo/ngx-permission/branch/master/graph/badge.svg)](https://codecov.io/gh/TekVanDo/ngx

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
ngx-permission
510.2.15 years ago5 years agoMinified + gzip package size for ngx-permission in KB

Readme

ngx permission
Build Status codecov npm version devDependency Status GitHub issues GitHub stars GitHub license

Table of contents

About

Angular 2 or Angular 4 implementation of 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<boolean>
};
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: `
onlyForRoles="'user'">user can see this
<div *onlyForRoles="['admin']">user can't see this</div>`
}) 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

``` ```

Documentation

All documentation is auto-generated from the source via 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 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