I have a simple model named "test" that looks like this:
export default DS.Model.extend ({
name: DS.attr('string')
})
My model hook in the "test" route is defined as follows:
export default Ember.Route.extend({
model() {
return this.store.createRecord('test');
}
});
I tried to assign an initial value to model.name in the "test" controller, but I can't get the 'set' to work.
export default Ember.Controller.extend({
init: function() {
let mod = this.get('model');
this.set (mod.name, "dummyName");
}
})
Ember inspector says mod=null. What am I doing wrong?
Update: I tried the 4 syntax changes as recommended in the comments below. None seem to work. I get the following error messages for each:
None of the 4 suggested syntaxes seem to work. I get the following error messages for each:
- Assertion Failed: Path 'model.name' must be global if no obj is given. Error: Assertion Failed: Path 'model.name' must be global if no obj is given.
- You need to provide an object and key to `set`. Error: Assertion Failed: You need to provide an object and key to `set`.
- Cannot read property 'set' of null TypeError: Cannot read property 'set' of null
- object in path "model" could not be found or was destroyed. Error: Property set failed: object in path "model" could not be found or was destroyed.
Seems to be telling me that 'model' is null for some reason.
Update:My controller actually looks like this:
import Ember from 'ember';
export default Ember.Controller.extend({
init: function() {
this.set ('model.name', 'dummyName');
},
actions: {
save() {
this.get('model').save();
this.transitionToRoute('scenarios');
return false;
},
cancel(){
this.transitionToRoute('scenarios');
return false;
}
}
});
With this controller, I get this error:
Property set failed: object in path "model" could not be found or was destroyed. Error: Property set failed: object in path "model" could not be found or was destroyed.
If I took out the 'init' hook, the 'save' & 'cancel' actions works fine. Naming seems to be ok; I used ember-cli pods to generate the initial code
Is 'model' loaded at the time when the controller's 'init' hook is called?