Skip to content

Instantly share code, notes, and snippets.

@eddie-ruva
Last active February 22, 2017 20:05
Show Gist options
  • Save eddie-ruva/47ad8737cb5a8f2c7e39fa957794c7a5 to your computer and use it in GitHub Desktop.
Save eddie-ruva/47ad8737cb5a8f2c7e39fa957794c7a5 to your computer and use it in GitHub Desktop.
Toggle switch
import Ember from 'ember';
export default Ember.Component.extend({
isChecked: false,
actions: {
onChange() {
this.toggleProperty('isChecked');
this.sendAction('onInteraction');
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
obj: {
isChecked: true
},
actions: {
myAction() {
this.toggleProperty('unboundIsChecked');
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
// With bound value
{{my-component isChecked=obj.isChecked}}
{{obj.isChecked}}
// Without bound value
{{my-component isChecked=true onInteraction=(action 'myAction')}}
{{unboundIsChecked}}
<label>Switch</label>
{{input type="checkbox" checked=isChecked change=(action "onChange")}}
{
"version": "0.11.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.10.2",
"ember-data": "2.11.0",
"ember-template-compiler": "2.10.2",
"ember-testing": "2.10.2"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment