Skip to content

Instantly share code, notes, and snippets.

@kumkanillam
Last active July 29, 2016 18:36
Show Gist options
  • Save kumkanillam/776ffb2be7e129655ef62e59b2dc8697 to your computer and use it in GitHub Desktop.
Save kumkanillam/776ffb2be7e129655ef62e59b2dc8697 to your computer and use it in GitHub Desktop.
Service - Array observer sample
import Ember from 'ember';
export default Ember.Controller.extend({
cart:Ember.inject.service(),
actions:{
addEntry(){
this.get('cart').addEntry();
}
}
});
import Ember from 'ember';
export default Ember.Service.extend({
bucket:['initial'],
addEntry(){
console.log('entry added');
this.get('bucket').pushObject('added');
},
bucketListener: Ember.observer('bucket.@each',function(){
Ember.run.once(this,'bucketChange');
}),
bucketChange(){
console.log('bucketChange');
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<button {{action "addEntry" }}> add entry </button>
<br>
{{outlet}}
<br>
<br>
{
"version": "0.10.3",
"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.7.0",
"ember-data": "2.7.0",
"ember-template-compiler": "2.7.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment