I've defined some properties in a controller for a pagination:
import Ember from 'ember';
export default Ember.ArrayController.extend({
limit: 1,
skip: 0,
pageSize: 1
}
});
I'd like to access limit
in the Route's model
-function but I don't know how.
import Ember from 'ember';
export default Ember.Route.extend({
model: function(params) {
console.log(this.get('controller').get('limit')) <- doesnt work for example
return this.store.find('post', {limit: 1,
sort:'createdAt desc'});
}
});
Maybe you should take a look at the queryParams option (http://emberjs.com/guides/routing/query-params/).
With query params you can set the limit to be a query param in your URL like http://yourdomain.com/someroute?limit=15
.
Your controller will become:
export default Ember.ArrayController.extend({
queryParams: ['limit'], // Here you define your query params
limit: 1 // The default value to use for the query param
});
You route will become:
export default Ember.Route.extend({
model: function(params) {
return this.store.find('post', {
limit: params.limit, // 'limit' param is available in params
sort:'createdAt desc'
});
}
});
Alternative:
If you don't want to use query params, another solution might be to define the limit property in one of the parent route's controller. By doing so you can access the property in the model hook by doing:
this.controllerFor('parentRoute').get('limit');