Primitives
The search primitive is a form control that allows users to enter a search query and clear the input.
Import the Search primitives from ng-primitives/search.
import { NgpSearch, NgpSearchClear } from 'ng-primitives/search';
Assemble the search directives in your template.
<div ngpFormField>
<label ngpLabel>Label</label>
<div ngpSearch>
<input ngpInput type="search" />
<button ngpSearchClear ngpButton aria-label="Clear search">Clear</button>
</div>
</div>
Create a search component that uses the NgpSearch directive.
Generate a reusable search component using the Angular CLI.
ng g ng-primitives:primitive search
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.The following directives are available to import from the ng-primitives/search package:
| Attribute | Description |
|---|---|
data-empty |
Applied when the input is empty. |
| Attribute | Description |
|---|---|
data-empty |
Applied when the search field is empty. |
Adheres to the Search WAI-ARIA design pattern.
Copyright © 2026 Angular Primitives
This site is powered by Netlify