Skip to content

Instantly share code, notes, and snippets.

@feanor07
Last active April 4, 2017 11:45
Show Gist options
  • Save feanor07/998456ae93e2db491c7a3776abebb4ba to your computer and use it in GitHub Desktop.
Save feanor07/998456ae93e2db491c7a3776abebb4ba to your computer and use it in GitHub Desktop.
Stackoverflow Question #43200191
import Ember from 'ember';
export default Ember.Component.extend({
myService: Ember.inject.service(),
didDestroyElement() {
console.log('@didDestroyElement');
},
willDestroyElement() {
console.log('@willDestroyElement');
},
willClearRender() {
console.log('@willClearRender');
},
myObserver: Ember.observer('myService.total', function(){
console.log('@observer');
}),
actions: {
removeFromDOM() {
this.$().remove();
this.destroy();
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
myService: Ember.inject.service(),
actions: {
incrementTotalOfService() {
this.get('myService').incrementProperty('total');
}
}
});
import Ember from 'ember';
export default Ember.Service.extend({
total: 0
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
{{my-component}}
<button onclick={{action 'incrementTotalOfService'}}>Increment service's total to see component's observer</button>
<br>
<br>
{{yield}}
Click button below to remove this component from DOM!
Total of service is :{{myService.total}}
<br>
<button onclick={{action 'removeFromDOM'}}>Remove</button>
{
"version": "0.12.1",
"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.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment