Skip to content

Instantly share code, notes, and snippets.

@manoharank
Last active December 23, 2015 13:09
Show Gist options
  • Save manoharank/6640182 to your computer and use it in GitHub Desktop.
Save manoharank/6640182 to your computer and use it in GitHub Desktop.
// accessing controller in route's model hook
App.PostsRoute = Em.Route.extend({
model: function() {
// getPosts will return a promise
return this.get('controller').getPosts();
}
});
App.PostsController = Ember.ArrayController.extend({
getPosts: function() {
var self = this;
return ajax('/posts', {
'page': this.get('page'),
'sort_column': this.get('sort_column'),
'sort_order': this.get('sort_order')
}).then(function(json) {
self.set('content', json.posts);
});
},
getPostsAgain: function() {
Ember.run.once(this, 'getPosts');
}.observes('page', 'sort_column', 'sort_order');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment