Skip to content

Instantly share code, notes, and snippets.

@Leooo
Created October 26, 2015 15:19
Show Gist options
  • Save Leooo/9811b4d9faacf04636f5 to your computer and use it in GitHub Desktop.
Save Leooo/9811b4d9faacf04636f5 to your computer and use it in GitHub Desktop.
attrbutes disappearing when observer on model
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle',
_test: function(){
var myModel=this.store.createRecord("myModel2",{});
console.log(myModel);
myModel.set("attr1",2);
console.log(myModel._internalModel);
console.log(Ember.get(myModel.constructor,"attributes"));
}.on('init'),
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
import DS from 'ember-data';
export default DS.Model.extend({
attr1: DS.attr("number",{defaultValue: 0,fromServer: 1}),
attr2: DS.attr("string"),
});
import DS from 'ember-data';
import myModel from './my-model'
export default myModel.extend({
attr3: DS.attr("string"),
_observesAtt1: function(){
console.log(this.get("attr1"));
}.observes('attr1'),
});
{
"version": "0.4.14",
"EmberENV": {
"FEATURES": {}
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.1.0/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.1.0/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.1.0/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment