MCPcopy
hub / github.com/ng-select/ng-select

github.com/ng-select/ng-select @v23.2.0 sqlite

repository ↗ · DeepWiki ↗ · release v23.2.0 ↗
531 symbols 1,093 edges 96 files 2 documented · 0%
README

npm version Coverage Status gzip size ng-select channel on discord

Angular ng-select - Lightweight all in one UI Select, Multiselect and Autocomplete

See Demo page.


Versions

Warning: Do not use versions 15.2.0, 16.0.0, 17.0.0, 18.0.0, 19.0.0, 20.0.0 as they contain unresolved issues

Angular ng-select
>=22.0.0 <23.0.0 v22.x.x
>=21.0.0 <22.0.0 v21.x.x
>=20.0.0 <21.0.0 <=15.1.3, >=20.0.1
>=19.0.0 <20.0.0 v14.x
>=18.0.0 <19.0.0 v13.x
>=17.0.0 <18.0.0 v12.x
>=16.0.0 <17.0.0 v11.x
>=15.0.0 <16.0.0 v10.x
>=14.0.0 <15.0.0 v9.x
>=13.0.0 <14.0.0 v8.x
>=12.0.0 <13.0.0 v7.x
>=11.0.0 <12.0.0 v6.x
>=10.0.0 <11.0.0 v5.x
>=9.0.0 <10.0.0 v4.x
>=8.0.0 <9.0.0 v3.x
>=6.0.0 <8.0.0 v2.x
v5.x.x v1.x

Browser Support

ng-select supports all browsers supported by Angular. For current list, see https://angular.io/guide/browser-support#browser-support. This includes the following specific versions:

Chrome  2 most recent versions
Firefox latest and extended support release (ESR)
Edge    2 most recent major versions
Safari  2 most recent major versions
iOS 2 most recent major versions
Android 2 most recent major versions

Table of contents

Features

  • [x] Custom binding to property or object
  • [x] Custom option, label, header and footer templates
  • [x] Virtual Scroll support with large data sets (>5000 items).
  • [x] Infinite scroll
  • [x] Keyboard navigation
  • [x] Multiselect
  • [x] Flexible autocomplete with client/server filtering
  • [x] Custom search
  • [x] Custom tags
  • [x] Append to
  • [x] Group items
  • [x] Output events
  • [x] Accessibility
  • [x] Good base functionality test coverage
  • [x] Themes

Warning

Library is under active development and may have API breaking changes for subsequent major versions after 1.0.0.

Getting started

Step 1: Install ng-select:

NPM

npm install --save @ng-select/ng-select

Yarn

yarn add @ng-select/ng-select

PNPM

pnpm add @ng-select/ng-select

Step 2:

Standalone: Import NgSelectComponent and other necessary directives directly:

import { NgLabelTemplateDirective, NgOptionTemplateDirective, NgSelectComponent } from '@ng-select/ng-select';
import { FormsModule } from '@angular/forms';

@Component({
    selector: 'example',
    standalone: true,
    template: './example.component.html',
    styleUrl: './example.component.scss',
    imports: [NgLabelTemplateDirective, NgOptionTemplateDirective, NgSelectComponent],
})
export class ExampleComponent {}

NgModule: Import the NgSelectModule and angular FormsModule module:

import { NgSelectModule } from '@ng-select/ng-select';
import { FormsModule } from '@angular/forms';

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

Step 3: Include a theme:

To allow customization and theming, ng-select bundle includes only generic styles that are necessary for correct layout and positioning. To get full look of the control, include one of the themes in your application. If you're using the Angular CLI, you can add this to your styles.scss or include it in .angular-cli.json (Angular v5 and below) or angular.json (Angular v6 onwards).

@import '~@ng-select/ng-select/themes/default.theme.css';
// ... or
@import '~@ng-select/ng-select/themes/material.theme.css';

Step 4 (Optional): Configuration

You can also set global configuration and localization messages by injecting NgSelectConfig service, typically in your root component, and customize the values of its properties in order to provide default values.

  constructor(private config: NgSelectConfig) {
      this.config.notFoundText = 'Custom not found';
      this.config.appendTo = 'body';
      // set the bindValue to global config when you use the same
      // bindValue in most of the place.
      // You can also override bindValue for the specified template
      // by defining `bindValue` as property
      // Eg : <ng-select bindValue="some-new-value"></ng-select>
      this.config.bindValue = 'value';
  }

Usage

Define options in your consuming component:

@Component({...})
export class ExampleComponent {

    selectedCar: number;

    cars = [
        { id: 1, name: 'Volvo' },
        { id: 2, name: 'Saab' },
        { id: 3, name: 'Opel' },
        { id: 4, name: 'Audi' },
    ];
}

In template use ng-select component with your options


<ng-select [(ngModel)]="selectedCar">
    @for (car of cars; track car.id) {
    <ng-option [value]="car.id">{{car.name}}</ng-option>
    }
</ng-select>


<ng-select [items]="cars" bindLabel="name" bindValue="id" [(ngModel)]="selectedCar"> </ng-select>

For more detailed examples see Demo page

SystemJS

If you are using SystemJS, you should also adjust your configuration to point to the UMD bundle.

In your systemjs config file, map needs to tell the System loader where to look for ng-select:

map: {
  '@ng-select/ng-select': 'node_modules/@ng-select/ng-select/bundles/ng-select.umd.js',
}

API

Inputs

Input Type Default Required Description
[addTag] boolean \| ((term: string) => any \| Promise<any>) false no Allows to create custom options.
addTagText string Add item no Set custom text when using tagging
appearance string underline no Allows to select dropdown appearance. Set to outline or fill for Material form-field styles (applies only to Material theme)
appendTo string null no Append dropdown to body or any other element using css selector. For correct positioning body should have position:relative
bufferAmount number 4 no Used in virtual scrolling, the bufferAmount property controls the number of items preloaded in the background to ensure smoother and more seamless scrolling.
bindValue string - no Object property to use for selected model. By default binds to whole object.
bindLabel string label no Object property to use for label. Default label
[closeOnSelect] boolean true no Whether to close the menu when a value is selected
clearAllText string Clear all no Set custom text for clear all icon title
[clearable] boolean true no Allow to clear selected value. Default true
[clearOnBackspace] boolean true no Clear selected values one by one when clicking backspace. Default true
[compareWith] (a: any, b: any) => boolean (a, b) => a === b no A function to compare the option values with the selected values. The first argument is a value from an option. The second is a value from the selection(model). A boolean should be returned.
dropdownPosition bottom | top | auto auto no Set the dropdown position on open
[fixedPlaceholder] boolean false no Set placeholder visible even when an item is selected
[groupBy] string | Function null no Allow to group items by key or function expression
[groupValue] (groupKey: string, children: any[]) => Object - no Function expression to provide group value
[selectableGroup] boolean false no Allow to select group when groupBy is used
[selectableGroupAsModel] boolean true no Indicates whether to select all children or group itself
[items] Array<any> [] yes Items array
[loading] boolean - no You can set the loading state from the outside (e.g. async items loading)
loadingText string Loading... no Set custom text when for loading items
labelForId string - no

Extension points exported contracts — how you extend this code

SelectionModel (Interface)
(no doc) [2 implementers]
src/ng-select/lib/selection-model.ts
Person (Interface)
(no doc)
src/demo/assets/stackblitz/data.service.ts
NgOption (Interface)
(no doc)
src/ng-select/lib/ng-select.types.ts
Person (Interface)
(no doc)
src/demo/app/examples/data.service.ts
ItemsRangeResult (Interface)
(no doc)
src/ng-select/lib/ng-dropdown-panel.service.ts
Example (Interface)
(no doc)
src/demo/app/examples/examples.ts
PanelDimensions (Interface)
(no doc)
src/ng-select/lib/ng-dropdown-panel.service.ts
Event (Interface)
(no doc)
src/demo/app/examples/output-events-example/output-events-example.component.ts

Core symbols most depended-on inside this repo

select
called by 390
src/ng-select/lib/selection-model.ts
tickAndDetectChanges
called by 386
src/ng-select/testing/helpers.ts
getNgSelectElement
called by 107
src/ng-select/testing/helpers.ts
triggerKeyDownEvent
called by 106
src/ng-select/testing/helpers.ts
filter
called by 94
src/ng-select/lib/items-list.ts
selectOption
called by 69
src/ng-select/testing/helpers.ts
detectChanges
called by 59
src/ng-select/lib/ng-select.component.ts
open
called by 42
src/ng-select/lib/ng-select.component.ts

Shape

Method 302
Class 186
Function 34
Interface 8
Enum 1

Languages

TypeScript100%

Modules by API surface

src/ng-select/lib/ng-select.component.ts74 symbols
src/ng-select/lib/items-list.ts37 symbols
src/ng-select/lib/ng-dropdown-panel.component.ts34 symbols
src/ng-select/lib/ng-select.component.spec.ts30 symbols
src/ng-select/lib/ng-templates.directive.ts29 symbols
src/ng-select/lib/selection-model.ts15 symbols
src/demo/app/examples/output-events-example/output-events-example.component.ts14 symbols
src/demo/app/shared/example-viewer/stackblitz-button/stackblitz.service.ts10 symbols
src/ng-select/testing/mocks.ts8 symbols
src/ng-select/testing/helpers.ts8 symbols
src/ng-select/lib/ng-dropdown-panel.service.ts8 symbols
src/demo/assets/stackblitz/data.service.ts8 symbols

Dependencies from manifests, versioned

@angular/animations22.0.4 · 1×
@angular/build22.0.4 · 1×
@angular/cdk22.0.2 · 1×
@angular/cli22.0.4 · 1×
@angular/common22.0.4 · 1×
@angular/compiler22.0.4 · 1×
@angular/compiler-cli22.0.4 · 1×
@angular/core22.0.4 · 1×
@angular/forms22.0.4 · 1×
@angular/language-service22.0.4 · 1×
@angular/localize22.0.4 · 1×
@angular/material22.0.2 · 1×

For agents

$ claude mcp add ng-select \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact