Basic Usage
Checked State
Sizes
Switches come in two sizes:With Actions
Theon_change parameter runs actions when the switch is toggled. The $event variable is true when switched on, false when off. Here, toggling the switch updates a separate status message:
Disabled State
Reading the Value
Use.rx to get a reactive reference to the switch’s boolean state. The .then() pipe converts true/false into display-friendly strings:
Toggle the switch and the input updates to reflect the current state.
API Reference
Switch Parameters
Label text displayed next to the switch.
Whether the switch is on.
Switch size:
"default", "sm".State key for the switch’s checked state. Auto-generated if not provided. Use
.rx to reference the switch’s boolean state in other components without specifying the name explicitly.Whether the switch is non-interactive.
Whether a selection is required for form submission.
Action(s) to execute when toggled.
$event is true when on, false when off.Additional Tailwind CSS classes appended to the component’s built-in styles.
Protocol Reference
Switch