Skip to content

Instantly share code, notes, and snippets.

@RecoX
Created June 5, 2018 10:24
Show Gist options
  • Save RecoX/8c80d6aaa6f07a1e5f418480315cdf7b to your computer and use it in GitHub Desktop.
Save RecoX/8c80d6aaa6f07a1e5f418480315cdf7b to your computer and use it in GitHub Desktop.
Observer
import Ember from 'ember';
export default Ember.Controller.extend({
myService: Ember.inject.service('my-service'),
appName: 'Ember Twiddle',
init() {
this.get('myService');
}
});
import Ember from 'ember';
export default Ember.Service.extend({
init() {
this._super(...arguments);
console.log(123, this);
this.set('foo', 'bar');
this.set('bar', 'foo');
this.addObserver('foo', this , 'fooDidChange');
},
fooDidChange(sender, key, value, rev) {
console.log(sender, key);
// your code
console.log('1');
},});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{
"version": "0.14.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": "2.18.2",
"ember-template-compiler": "2.18.2",
"ember-testing": "2.18.2"
},
"addons": {
"ember-data": "2.18.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment