ons-switch

Switch component.

Usage #

<ons-switch checked></ons-switch>

See also #

Attributes #

Name Type
Default Value
Description
var String Variable name to refer this switch. Optional
modifier String The appearance of the switch. Optional
disabled Whether the switch should be disabled. Optional
checked Whether the switch is checked. Optional

Methods Summary #

Signature Description
isChecked() Returns true if the switch is ON.
setChecked(checked) Set the value of the switch. isChecked can be either true or false.
getCheckboxElement() Get inner input[type=checkbox] element.
on(eventName, listener) Add an event listener.
once(eventName, listener) Add an event listener that's only triggered once.
off(eventName, [listener]) Remove an event listener. If the listener is not specified all listeners for the event type will be removed.

Events Summary #

Name Description
change Fired when the value is changed.

Methods

isChecked(): Boolean #

Returns true if the switch is ON.

Returns: true if the switch is on.

setChecked(checked) #

Set the value of the switch. isChecked can be either true or false.

Parameters
Name Type Description
checked Boolean If true the switch will be set to on.

getCheckboxElement(): HTMLElement #

Get inner input[type=checkbox] element.

Returns: The underlying checkbox element.

on(eventName, listener) #

Add an event listener.

Parameters
Name Type Description
eventName String Name of the event.
listener Function Function to execute when the event is triggered.

once(eventName, listener) #

Add an event listener that's only triggered once.

Parameters
Name Type Description
eventName String Name of the event.
listener Function Function to execute when the event is triggered.

off(eventName, [listener]) #

Remove an event listener. If the listener is not specified all listeners for the event type will be removed.

Parameters
Name Type Description
eventName String Name of the event.
listener Function Function to execute when the event is triggered.

Events

change #

Fired when the value is changed.

Parameters
Name Type Description
event Object Event object.
event.switch Object Switch object.
event.value Boolean Current value.
event.isInteractive Boolean True if the change was triggered by the user clicking on the switch.

Discussion #