7.0.6 • Published 4 years ago

ng-select2-custom v7.0.6

Weekly downloads
11
License
-
Repository
github
Last release
4 years ago

npm version Downloads GitHub license

Select2

This Angular CLI module it's a fork of select2-component without Vue & React. For Vue or React, please use the original component.

Installation

npm i ng-select2-component --save

Requirements

  • Angular 7.0.0 and more

Demo

See a demo.

Features

  • select one
  • options or groups
  • scroll
  • local search
  • select by keyboard
  • disabled option
  • disabled component
  • hide search box
  • placeholder
  • multiple selection
  • material style
  • form binding

Usage

example

import { Select2Module } from "ng-select2-component";

@NgModule({
    imports: [BrowserModule, FormsModule, Select2Module],
    declarations: [MainComponent],
    bootstrap: [MainComponent],
})
class MainModule { }
<select2 [data]="data"
    [value]="value"
    (update)="update($event)">
</select2>

properties and events of the component

nametypedescription
dataSelect2Datathe data of the select2
valueSelect2Value?initial value
disabledboolean?whether the component is disabled
minCountForSearchnumber? = 6hide search box if options.length < minCountForSearch
placeholderstring?the placeholder string if nothing selected
customSearchEnabledboolean?will trigger search event, and disable inside filter
multipleboolean?select multiple options
hideSelectedItemsboolean?for multiple, remove selected values
resultMaxHeightstring?change the height size of results
material"" or trueenable material style
editPattern(str: string) => stringuse it for change the pattern of the filter search
ngModel/id/required/disabled/readonly/tabIndexjust like a select control
update(value: Select2UpdateValue) => voidtriggered when user select an option
open() => voidtriggered when user open the options
search(text: string) => voidtriggered when search text changed

select2 data structure

type Select2Data = (Select2Group | Select2Option)[];

interface Select2Group = {
    label: string;
    options: Select2Option[];
    classes?: string;
};

interface Select2Option = {
    value: Select2Value;
    label: string;
    disabled?: boolean;
    component?: string | Function; // the component
    classes?: string;
};

type Select2Value = string | number | boolean;

type Select2UpdateValue = Select2Value | Select2Value[];

Publishing the library

npm run build:lib
cd dist/ng-select2-component
npm publish

Update Demo

npm run build:demo

License

Like Angular, this module is released under the permissive MIT license. Your contributions are always welcome.

7.0.6

4 years ago

7.0.5

4 years ago