How to access ember model in on("init") in object controller? Its undefined in this case:
inititalise: function () {
// this.model is undefined
}.on("init"),
To define a new Ember class, call the extend() method on EmberObject : import EmberObject from '@ember/object'; const Person = EmberObject. extend({ say(thing) { alert(thing); } }); This defines a new Person class with a say() method.
In Ember Data, models are objects that represent the underlying data that your application presents to the user. Note that Ember Data models are a different concept than the model method on Routes, although they share the same name.
In Ember. js, controllers allow you to decorate your models with display logic. In general, your models will have properties that are saved to the server, while controllers will have properties that your app does not need to save to the server.
To define a new Ember class, call the extend() method on Ember. Object : App. Person = Ember.
The short answer is that you can't. Controllers are instantiated by the container before the route has had a chance to set the model on the controller. If this object controller is a controller set up automatically for you by Ember, you're not going to be able to access the model during initialization. Try observing the model
property instead.
I can't really find any documentation in the guides on this, so I'll link you to the source code. If you read the source for the setup
function, you'll see that generateController()
is called and then setupController()
is called some time later. Essentially, the controller is created, Ember does some work, then the model is set. Ember doesn't set the model for the controller on creation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With