Search code examples
javascriptember.jsroutespromiseember-router

Render immediately in Ember.js


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.


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/