Switch component.
<ons-switch checked></ons-switch>
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 |
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. |
Name | Description |
---|---|
change | Fired when the value is changed. |
Returns true if the switch is ON.
Returns: true if the switch is on.
Set the value of the switch. isChecked can be either true or false.
Name | Type | Description |
---|---|---|
checked | Boolean | If true the switch will be set to on. |
Get inner input[type=checkbox] element.
Returns: The underlying checkbox element.
Add an event listener.
Name | Type | Description |
---|---|---|
eventName | String | Name of the event. |
listener | Function | Function to execute when the event is triggered. |
Add an event listener that's only triggered once.
Name | Type | Description |
---|---|---|
eventName | String | Name of the event. |
listener | Function | Function to execute when the event is triggered. |
Remove an event listener. If the listener is not specified all listeners for the event type will be removed.
Name | Type | Description |
---|---|---|
eventName | String | Name of the event. |
listener | Function | Function to execute when the event is triggered. |
Fired when the value is changed.
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. |