Primitives
Toggle a button on and off.
Import the Toggle primitives from ng-primitives/toggle.
import { NgpToggle } from 'ng-primitives/toggle';
Assemble the toggle directives in your template.
<button ngpToggle [(ngpToggleSelected)]="selected">Toggle</button>
Create a reusable component that uses the toggle directives.
Generate a reusable toggle component using the Angular CLI.
ng g ng-primitives:primitive toggle
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/toggle package:
The following data attributes are applied to the ngpToggle directive:
| Attribute | Description |
|---|---|
data-selected |
Applied when the toggle is selected. |
data-disabled |
Applied when the toggle is disabled. |
Copyright © 2026 Angular Primitives
This site is powered by Netlify