I'm trying to share a Ember object between different controllers in order to 'decorate' it with more information as you go through the app.
In a simple Ember app I would just do:
App.UserDetails = Ember.Object.extend({name: 'Darryl', age: 26 });
App.DetailsRoute = Ember.Route.extend({
model: function () {
return App.UserDetails;
}
});
App.AccountRoute = Ember.Route.extend({
model: function () {
return App.UserDetails;
}
});
But I can't see I would organise this in Ember CLI
Thanks
You should use data persistence library like Ember Data, because it was designed for things like storing user details and there are tons of information how to do that, but you ask about sharing an object so:
You can use Ember.Service
:
Details service:
import Ember from 'ember';
export default Ember.Service.extend({
name: 'Darryl',
age: 26
});
Rest:
App.DetailsRoute = Ember.Route.extend({
details: Ember.inject.service(),
model: function () {
return this.get('details');
}
});
App.AccountRoute = Ember.Route.extend({
details: Ember.inject.service(),
model: function () {
return this.get('details');
}
});