Skip to content

Instantly share code, notes, and snippets.

@Serabe
Forked from tehmaestro/components.my-component.js
Created October 20, 2016 13:07
Show Gist options
  • Select an option

  • Save Serabe/ac1b0c843e59662590611ad640e4c948 to your computer and use it in GitHub Desktop.

Select an option

Save Serabe/ac1b0c843e59662590611ad640e4c948 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['classname-1', 'classname-2'],
classNameBindings: ['class3:classname-3','class4:classname-4'],
actions: {
// Toggle the class4 property, which makes the binding update
toggleClass: function(prop) {
this.toggleProperty(prop);
Ember.run.schedule('afterRender', () => {
this.set('classes', this.$().attr('class'));
});
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
{{my-component}}
<br>
<br>
<p>Classes are: {{classes}}</p>
<button {{action "toggleClass" "class3"}}>Add class3 with jQuery</button>
<button {{action "toggleClass" "class4"}}>Toggle class4 through binding</button>
{
"version": "0.10.6",
"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.8.2",
"ember-data": "2.9.0",
"ember-template-compiler": "2.8.2",
"ember-testing": "2.8.2"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment