ember.js - associating a model with a route in emberjs -


as understad, template in emberjs gets it's data controller. so, it's controller's job hold of model data , present template.

the docs here associate model route this:

app.favoritesroute = ember.route.extend({   model: function() {     // model array of of posts     return app.post.find();   } }); 

in case , arraycontroller automatically generated.


however, there's setupcontroller function. so, can :

app.favoritesroute = ember.route.extend({   setupcontroller: function(controller) {     controller.set('model', app.post.find());   } }); 

as first example given here do?

do 2 ways same thing?

do 2 ways same thing?

almost. in both cases controller's content property set result of app.post.find(). , both work.

that said, using model hook preferred way this. if model hook returns promise, router wait resolve before moving on. not case setupcontroller hook. want avoid async setupcontroller hook.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -