0.0.1-beta.12 • Published 4 months ago

@smplfrs/angular-select2 v0.0.1-beta.12

Weekly downloads
90
License
MIT
Repository
github
Last release
4 months ago

Prerequisites

Install JQuery

npm i -s jquery

Include JQuery in your angular.json file

"scripts": [
  "node_modules/jquery/dist/jquery.js"
],

Get started

Install package

npm i -s @smplfrs/angular-select2

Include default styles in your angular.json file

"styles": [
  "node_modules/select2/dist/css/select2.min.css"
],

Import the SmplSelect2Module in your app module

import { SmplSelect2Module } from '@smplfrs/angular-select2';
...
@NgModule({
  ...
  imports: [
    SmplSelect2Module
  ],
  ...
})

Usage

Static options

static-options.component.html

<select smplSelect2 static>
  <option value="1">Option 1</option>
  <option value="2">Option 2</option>
  <option value="3">Option 3</option>
</select>

Dynamic options

dynamic-options.component.html

<select smplSelect2 [dataSource]="dataSource">
</select>

dynamic-options.component.ts

dataSource = {
  data: [
    { id: 1, text: 'Option 1' },
    { id: 2, text: 'Option 2' },
    { id: 3, text: 'Option 3' }
  ]
};

Async data source

async-data.component.html

<select smplSelect2 [dataSource]="dataSource">
</select>

async-data.component.ts

dataSource = {
  ajaxFn: of([
    { id: 1, text: 'Option 1' },
    { id: 2, text: 'Option 2' },
    { id: 3, text: 'Option 3' }
  ]),
  ajaxDelay: 1000
};

API reference

Input

NameTypeDefaultDescription
smplSelect2Select2ConfigConfiguration options for the control.
staticbooleanfalseWhether dropdown options should be rendered from html <options> tags.
dataSourceSelect2DataSourceDynamic data source for dropdown options when static is set to false.
displayPropertystring'text'The property of dropdown option object used to display in selection panel.
valuePropertystring'id'The property of dropdown option object used as identifier.
placeholderstring'(NONE)'The placeholder for the control.

Output

NameTypeDescription
selectSelect2OptionEmitted when selection changed.

Class

Select2Config

See select2 configuration options.

Select2DataSource

NameTypeDescription
dataany[]A data array to render dropdown options.
ajaxFnObservable<any[]>An async data source called when opening the dropdown.
ajaxDelaynumberDelay time to execute ajaxFn.
dataTransformFn(data: any[]) => Select2Option[]Optional custom function to transform raw data into Select2Option.
0.0.1-beta.12

4 months ago

0.0.1-beta.11

4 months ago

0.0.1-beta.10

9 months ago

0.0.1-beta.9

2 years ago

0.0.1-beta.7

3 years ago

0.0.1-beta.8

3 years ago

0.0.1-beta.6

4 years ago

0.0.1-beta.5

4 years ago

0.0.1-beta.4

4 years ago

0.0.1-beta.3

4 years ago

0.0.1-beta.1

4 years ago

0.0.1-beta

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago