I am building a project management app using ember.js-pre3 ember-data revision 11.
How do I initialize a couple of controllers and make them available globally. For
In the latest version of ember (ember-1.0.0-pre.3.js) you can do this by declaring controller dependencies. Once a dependency has been declared, it will be accessible via the controllers
property. For example:
window.App = Ember.Application.create();
App.ApplicationController = Ember.Controller.extend({
needs: ['currentUser', 'users']
});
App.CurrentUserController = Ember.ObjectController.extend({
content: 'mike'
});
App.UsersController = Ember.ArrayController.extend({
content: ['mike', 'jen', 'sophia']
});
Since ApplicationController needs currentUser and users, those controllers are accessible via it's controllers
property and can be used from within the application template:
<script type="text/x-handlebars">
<p>Signed in as {{controllers.currentUser.content}}</p>
<h2>All Users:</h2>
<ul>
{{#each user in controllers.users}}
<li> {{user}} </li>
{{/each}}
</ul>
</script>
Here's a working example: http://jsfiddle.net/mgrassotti/mPYEX/
See https://github.com/emberjs/ember.js/blob/master/packages/ember-application/tests/system/controller_test.js for some examples