# @smplfrs/angular-select2

> Install [JQuery](https://www.npmjs.com/package/jquery) ``` npm i -s jquery ```

Latest version **0.0.1-beta.12** (published 2023-12-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install @smplfrs/angular-select2
pnpm add @smplfrs/angular-select2
yarn add @smplfrs/angular-select2
bun add @smplfrs/angular-select2
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1-beta.12 |
| Published | 2023-12-26 |
| First published | 2020-01-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 89.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | phuongnle, truxtrux |
| Keywords | angular, select2, typescript, directive |

## Links

- npm: https://www.npmjs.com/package/@smplfrs/angular-select2
- Repository: https://github.com/smplfrs/angular-select2
- Homepage: https://github.com/smplfrs/angular-select2#readme
- Issues: https://github.com/smplfrs/angular-select2/issues
- npm.io page: https://npm.io/package/@smplfrs/angular-select2

## Dependencies (2)

- [tslib](https://npm.io/package/tslib.md) ^2.3.0
- [select2](https://npm.io/package/select2.md) 4.0.13

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.0.1-beta.12 (latest) — 2023-12-26
- 0.1.1-beta.1 (beta) — 2024-12-04
- 0.1.1-beta.0 — 2024-11-25
- 0.0.1-beta.11 — 2023-12-26
- 0.0.1-beta.10 — 2023-08-14
- 0.0.1-beta.9 — 2022-09-01
- 0.0.1-beta.8 — 2021-02-25
- 0.0.1-beta.7 — 2021-02-25
- 0.0.1-beta.6 — 2020-11-02
- 0.0.1-beta.5 — 2020-10-21
- 0.0.1-beta.4 — 2020-10-19
- 0.0.1-beta.3 — 2020-09-01
- 0.0.1-beta.1 — 2020-01-03
- 0.0.1-beta — 2020-01-03

## README

# Prerequisites

Install [JQuery](https://www.npmjs.com/package/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

```typescript
import { SmplSelect2Module } from '@smplfrs/angular-select2';
...
@NgModule({
  ...
  imports: [
    SmplSelect2Module
  ],
  ...
})
```

## Usage

### Static options

**static-options.component.html**
```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**
```html
<select smplSelect2 [dataSource]="dataSource">
</select>
```

**dynamic-options.component.ts**
```typescript
dataSource = {
  data: [
    { id: 1, text: 'Option 1' },
    { id: 2, text: 'Option 2' },
    { id: 3, text: 'Option 3' }
  ]
};
```


### Async data source

**async-data.component.html**
```html
<select smplSelect2 [dataSource]="dataSource">
</select>
```

**async-data.component.ts**
```typescript
dataSource = {
  ajaxFn: of([
    { id: 1, text: 'Option 1' },
    { id: 2, text: 'Option 2' },
    { id: 3, text: 'Option 3' }
  ]),
  ajaxDelay: 1000
};
```

## API reference

### Input
| Name              | Type                                      | Default   | Description  |
| ------------------|-------------------------------------------|:---------:|--------------|
| `smplSelect2`     | [Select2Config](#select2config)           |           | Configuration options for the control. |
| `static`          | boolean                                   | false     | Whether dropdown options should be rendered from html `<options>` tags. |
| `dataSource`      | [Select2DataSource](#select2datasource)   |           | Dynamic data source for dropdown options when `static` is set to `false`. |
| `displayProperty` | string                                    | 'text'    | The property of dropdown option object used to display in selection panel. |
| `valueProperty`   | string                                    | 'id'      | The property of dropdown option object used as identifier. |
| `placeholder`     | string                                    | '(NONE)'  | The placeholder for the control. |


### Output
| Name      | Type          | Description  |
| ----------|---------------| -------------|
| `select`  | Select2Option | Emitted when selection changed.  |


### Class

#### Select2Config

See [select2 configuration options](https://select2.org/configuration/options-api).

#### Select2DataSource

| Name              | Type                              | Description  |
| ------------------|-----------------------------------| -------------|
| `data`            | any[]                             | A data array to render dropdown options.  |
| `ajaxFn`          | Observable<any[]>                 | An async data source called when opening the dropdown.  |
| `ajaxDelay`       | number                            | Delay time to execute `ajaxFn`.  |
| `dataTransformFn` | (data: any[]) => Select2Option[]  | Optional custom function to transform raw data into Select2Option.  |

---
_Source: https://npm.io/package/@smplfrs/angular-select2 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
