Primitives
Perform state toggling.
Import the Switch primitives from ng-primitives/switch.
import { NgpSwitch, NgpSwitchThumb } from 'ng-primitives/switch';
Assemble the switch directives in your template.
<button ngpSwitch [(ngpSwitchChecked)]="checked">
<span ngpSwitchThumb></span>
</button>
Create a reusable component that uses the switch directives.
Generate a reusable switch component using the Angular CLI.
ng g ng-primitives:primitive switch
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.Here are some additional examples of how to use the Switch primitives.
The switch automatically integrates with the form field primitives.
The following directives are available to import from the ng-primitives/switch package:
Adheres to the WAI-ARIA switch design pattern.
Copyright © 2026 Angular Primitives
This site is powered by Netlify