Primitives
Import the FormField primitives from ng-primitives/form-field.
import {
NgpFormField,
NgpLabel,
NgpDescription,
NgpError,
NgpFormControl,
} from 'ng-primitives/form-field';
Assemble the form-field directives in your template.
<div ngpFormField>
<label ngpLabel>Label</label>
<!-- Typically ngpFormControl would not be used directly, but a primitive like ngpInput would be used instead -->
<input ngpFormControl />
<p ngpDescription>Description</p>
<p ngpError ngpErrorValidator="required">Error</p>
</div>
Create a reusable component that uses the NgpFormField directive.
Generate a reusable form-field component using the Angular CLI.
ng g ng-primitives:primitive form-field
path: The path at which to create the component file.prefix: The prefix to apply to the generated component selector.component-suffix: The suffix to apply to the generated component class name.file-suffix: The suffix to apply to the generated component file name. Defaults to component.example-styles: Whether to include example styles in the generated component file. Defaults to true.The following directives are available to import from the ng-primitives/form-field package:
The label and description elements should be associated with the form control using the aria-labelledby and aria-describedby attributes, respectively. This will ensure that screen readers can provide the necessary context to users.
Copyright © 2026 Angular Primitives
This site is powered by Netlify