Reputation: 1013
I am running ember 1.6.0. The docs say that since 1.6.0 there has been a property on Ember Route objects which contains the controller defined for that route. How ever when I call that property, I get undefined.
App.PhotosRoute = App.LibraryRoute.extend({
model: function () {
//blah
},
afterModel: function () {
this.controller // => undefined
var _this = this
App.store.find('batch').then(function (batches) {
if (batches.content.length) {
//unrelated note: _this returns "ReferenceError: _this is not defined" here which really confuses me
}
});
}
});
Obviously i could do something terrible like App.container.lookup to get the controller here but I'm really wondering why I can't just call the controller property.
My two guesses: a) this property is set at some point afterModel runs b) the fact that my route inherits from a route other than EmberRoute is causing some problem
Also, as an aside, if anyone could school me up on some javascript basics as to why the variable "_this" I'm defining is not available in the context of my promise return it would also be appreciated
Upvotes: 0
Views: 314
Reputation: 1273
afterModel
is called before setupController
, so the controller is not set yet, perhaps move your code there, remember to call this._super(model, controller);
.
And as always with ember use the getters and setters.
Upvotes: 2