Model isn't accessible in controller

I used the setupController hook in my route file, and this works in so much as I can access this.model in getters and methods. However, I notice I can’t do the same within a constructor or within a filter property. Using console.log(this.model) in the constructor will only return as undefined. I’m sure there’s something extremely obvious that I’m missing.

Here’s my route file. filetimeline_route

Here’s my controller file.

I would not expect the model to be available in the controller constructor. Typically a constructor is the very first code run “on” a class instance, so setupController can’t be run until the controller is constructed.

The filter property I’m not sure about, it’s possible it would be computed once before the model resolved but should be recomputed when the model is set (if it’s set up properly).

Is there anything in particular you’re trying to accomplish?

1 Like

Can you return a set of promises like that, in a normal javascript array? How does Ember know they have all resolved or not. I normally use .all or .hash.

1 Like

Oh yeah that’s a good catch too. You’d either want to return the array wrapped in RSVP.all or, since you’re using an async model hook throw in a couple awaits before pushing the objects into the array. You probably want to make sure the model has resolved before setupController is called which will only happen if the model hook is actually waiting/blocking.

1 Like

Thank you, both of you. The issue I was having was resolved by using a hash in the model hook of my route file rather than a normal array.

1 Like