Primitives

Select

A select is a form control that allows users to select options from a list. This primitive enhances the native select element with improved accessibility and interaction handling for hover and focus.

Import

Import the Select primitives from ng-primitives/select.

import { NgpSelect } from 'ng-primitives/select';

Usage

Assemble the select directives in your template.

<select ngpSelect>
  <option value="24">24 hours</option>
  <option value="12">12 hours</option>
</select>

Reusable Component

Create a reusable component that uses the NgpSelect directive.

import { Component } from '@angular/core';
import { Select } from './select';

@Component({
  selector: 'app-root',
  imports: [Select],
  template: `
    <select app-select>
      <option value="1">Option 1</option>
      <option value="2">Option 2</option>
    </select>
  `,
})
export default class App {}

Schematics

Generate a reusable select component using the Angular CLI.

ng g ng-primitives:primitive select

Options

  • 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.

Examples

Here are some additional examples of how to use the Select primitives.

Select Form Field

The select automatically integrates with the form field primitives.

Choose between 12-hour and 24-hour time formats.

API Reference

The following directives are available to import from the ng-primitives/select package:

NgpSelect

Apply the `ngpSelect` directive to a select element that you want to enhance.

  • Selector: select[ngpSelect]
  • Exported As: ngpSelect
ngpSelectDisabled
boolean

Whether the select is disabled.

Data Attributes

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 © 2025 Angular Primitives