Skip to content

Instantly share code, notes, and snippets.

@sheriffderek
Created February 18, 2018 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sheriffderek/9582b3fb1bacd111295654a34b54912e to your computer and use it in GitHub Desktop.
Save sheriffderek/9582b3fb1bacd111295654a34b54912e to your computer and use it in GitHub Desktop.
Welcome-like component
import Ember from 'ember';
export default Ember.Component.extend({
// It's key to understand that this is a
// "hash" of properties...
// and not a block for javascript (see click)
// Element
tagName: 'asisde',
classNames: ['example-component'],
// Attributes
greeting: 'Hey',
name: 'AshaM',
selected: false,
// Styles
classNameBindings: ['selected:fancy'],
click() {
var greeting = this.get('greeting');
alert( greeting + '! you clicked me!');
this.toggleProperty('selected');
},
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
.example-component {
display: block;
border: 1px solid gray;
border-radius: 10px;
padding: 10px;
margin-bottom: 20px;
}
.example-component h1 {
font-size: 20px;
margin: 0;
padding: 0;
}
.example-component.fancy {
background: lightgreen;
color: white;
}
{{!-- using defaults --}}
{{example-component}}
{{!-- you can also 'pass in' arguments like a JS function --}}
{{example-component greeting="Hola"}}
{{!-- lots of attributes get messy on one line --}}
{{example-component
greeting="Hola"
name='@sheriffderek'
selected=true
}}
<h2>{{greeting}}, {{name}}! I'm a component - just like the welcome page</h2>
{{!-- just some simple text... and a dynamic attribute of name --}}
{
"version": "0.13.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.16.2",
"ember-template-compiler": "2.16.2",
"ember-testing": "2.16.2"
},
"addons": {
"ember-data": "2.16.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment