Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ngx-roles-selector

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngx-roles-selector

An Angular Component that allows the user to select multiple roles of interest from a list of specified roles, separated by different permissions name.

  • 0.0.5
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Roles Selector

An Angular Component that allows the user to select multiple roles of interest from a list of specified roles, separated by different permissions name.

Dependencies

  • Angular
  • Angular material

Features

  • Component rendering roles and permission.
  • Component rendering pre selected roles and permission.
  • Tags to show which Roles have been selected.
  • Bagdes on each tag to show number of permission selected for a role.
  • Add and remove roles and permissions via checkboxes

Example

Roles Selector Example

Demo

Demo Application

Installation

After installing the above dependencies. Install ngx-roles-selector via.

npm i ngx-roles-selector 

Once installed you need to import our main module in your application module:

import { RolesSelectorModule } from 'ngx-roles-selector';


 

@NgModule({
  declarations: [AppComponent, ...],
  imports: [RolesSelectorModule, ...],
  bootstrap: [AppComponent]
})
export class AppModule {
}

Usage

ngx-roles-selector.

        <form  [formGroup]="form">
            ....
           <ngx-roles-selector 
                [formArrayName]="'roles'"
                [roleList]="roleList" 
                [form]="form"
                [permittedRoles]  = "permittedRoles"
                [permissions] = "permissions"
                [showTags] = "true"
            >

            </ngx-roles-selector >
            ....
        </form>

Create your form in the component ts file. Inside the constructor of your component.ts file create a form with empty roles formarray via

  constructor(
    private fb: FormBuilder
  ) {

    this.form = this.fb.group({
    
      roles: this.fb.array([])
      
    })
  }

Make sure to import missing FormBuilder import.

Declare and initialize roleList property sample:


  roleList: any[] = [
    {
      name: "Inventory",
    },
    {
      name: "Tasks"
    },
    {
      name: "Payroll"
    },
    {
      name: "Users"
    },
    {
      name: "Workflow"
    },
    {
      name: "Requisition"
    },
    {
      name: "Employees"
    }
  ]

Declare and initialize permissions property, sample:

 permissions = ['read', 'write', 'create', 'delete',"export","import"]

Declare and initialize existing roles and permissions if available, sample:

  permittedRoles = [
    {
      name: "Payroll",
      read: true,
      write: true,
      create: true,
      delete: true,
      export: true, 
      import: true, 

    },

  ]

Finnaly create a get method to return roles as formarray, sample:


  get roles() {
    return this.form.get('roles') as FormArray;
  }

Keywords

FAQs

Package last updated on 14 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc