Ive heard about, that controlers gonna get deprecated some day. So im trying to just use components for everything.
But if you'r going to use some calculated properties all over the whole application, where would you implement it?
In general, I would use an application-controller and put in in there.
What is the best practice?
I think services are what you are looking for.
Have a look at the following:
http://www.hutchinson.io/ember-services-and-dependency-injection/
Here's how I use a service to store application configuration (user permissions/roles, defaults, etc.):
/app/services/configuration.js
import Ember from 'ember';
export default Ember.Service.extend({
roles: ['Administrator', 'Manager', 'User', 'View-only'],
// ...
});
/app/initializers/configuration-service.js
export function initialize(container, application) {
application.inject('route', 'configuration', 'service:configuration');
application.inject('controller', 'configuration', 'service:configuration');
}
export default {
name: 'configuration-service',
initialize: initialize
};
Which I then access in controllers and routes like this:
export default Ember.Controller.extend({
allRoles: function() {
return this.configuration.roles;
}).property();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With