Question

I have a route where model method returns a promise. According to Ember.js spec, this results in certain operations (rendering, setupController) being delayed until the promise is resolved.

This is no good in my case. I would like the view to render immediately. Then, once the model becomes available, I would like to set a property on the controller. This would result in re-rendering of the appropriate parts of the view.

What would be the correct way of doing this? In particular I don't want to operate on promises inside my controller. Ideally I would have all the dependency setup done inside a route, just as is the case now.

Was it helpful?

Solution

Solved it using LoadingRoute, example here:

http://jsfiddle.net/u3w9Q/

Note that newer versions (>= 1.3 I think) also support more sophisticated scenarios. More details here:

http://emberjs.com/guides/routing/loading-and-error-substates/

OTHER TIPS

Had a similar issue. I got around the immediate issue of rendering by waiting for the didInsertElement to fire on the View and then called an action on the controller by using this.get('controller').send('actionInsideControllerHere');. That action calls one of my models (objects) and also changes a property on the controller to show "spinners" over components which were waiting for data. There might be a better way to do this, but that is what I came up with for now. Let me know if that works for ya.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top