Skip to content

Instantly share code, notes, and snippets.

@k-fish
Last active April 8, 2019 18:25
Show Gist options
  • Save k-fish/a037861a5e830313f7bb3080dd25a708 to your computer and use it in GitHub Desktop.
Save k-fish/a037861a5e830313f7bb3080dd25a708 to your computer and use it in GitHub Desktop.
Example of initialization of value on component render
import Ember from 'ember';
export default Ember.Component.extend({
classNames: "component",
countWas7: false,
init() {
this._super(...arguments);
if (this.count == 7) {
this.set('countWas7', true);
}
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.component {
padding: 10px;
border-radius: 5px;
border: 1px solid black;
margin: 10px;
}
{{example-component count=7}}
{{example-component count=8}}
<h2>Example Component</h2>
<h4>Count:</h4>
<div>{{count}}</div>
<h4>Count was 7 on initialization:</h4>
<div>{{countWas7}}</div>
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment