Primitives
A select is a form control that allows users to select options from a list.
Import the Select primitives from ng-primitives/select.
import {
NgpSelect,
NgpSelectDropdown,
NgpSelectPortal,
NgpSelectOption,
} from 'ng-primitives/select';
Assemble the select directives in your template.
<div ngpSelect>
<div *ngpSelectPortal ngpSelectDropdown>
<div ngpSelectOptionValue="option-1" ngpSelectOption>One</div>
<div ngpSelectOptionValue="option-2" ngpSelectOption>Two</div>
<div ngpSelectOptionValue="option-3" ngpSelectOption>Three</div>
</div>
</div>
Create a reusable component that uses the NgpSelect directive.
Generate a reusable select component using the Angular CLI.
ng g ng-primitives:primitive select
path: The path at which to create the component file.prefix: The prefix to apply to the generated component selector.componentSuffix: The suffix to apply to the generated component class name.fileSuffix: The suffix to apply to the generated component file name. Defaults to component.exampleStyles: Whether to include example styles in the generated component file. Defaults to true.Here are some additional examples of how to use the Select primitives.
The select can be used within a form field for better integration with form controls.
The native select is a simple wrapper around the native select element.
The select automatically integrates with the form field primitives.
The select component can be rendered inside a custom container. You can open DevTools and inspect the DOM to see it mounted within this container.
When dealing with large datasets (thousands of items), you can use TanStack Virtual or other virtualization libraries to efficiently render only the visible options, improving performance:
Options without a value do not perform any selection by default. You can use this to implement custom behavior, such as clearing the selection. These options are still included in keyboard navigation.
The following directives are available to import from the ng-primitives/select package:
| Attribute | Description |
|---|---|
data-hover |
Applied when the element is hovered. |
data-focus-visible |
Applied when the element is focused. |
data-disabled |
Applied when the element is disabled. |
Copyright © 2026 Angular Primitives
This site is powered by Netlify