Can anybody help me? How create object inside component for itself. ?
This is more or less a javascript issue — when you define the component and give one of the properties a value that is not a primitive (so, in your case, it’s an Object), that same object is used across all instances of that component.
So, one of the common patterns to resolve this is to use a computed property. Something like this:
App.FooTestComponent = Ember.Component.extend({
testObj: Ember.computed(function() {
return {
bool: true
};
}),
testBool: false,
actions: {
change: function() {
this.toggleProperty('testObj.bool');
this.toggleProperty('testBool');
}
}
});
In this case, the testObj
value is not calculated until sometime after the instance of the component is created (it’s actually created the first time something tries to retrieve that value).
Hope this helps!!
1 Like
Thanks very much for answer… )