ember-js-globally-available-controllers-like-currentuser
For SO POST http://stackoverflow.com/questions/14388249/ember-js-globally-available-controllers-like-currentuser
by wmarbut
HTML
<script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.rc.1/handlebars.min.js"></script>
<script src="https://raw.github.com/emberjs/ember.js/release-builds/ember-1.0.0-pre.3.js"></script>
<script src="https://gist.github.com/raw/75478d4d97cbc533a12f/9f8126fd97cbaa065046aa368afbcac4f42c8afc/ember-data-b411dc5a.js"></script>
<script type="text/x-handlebars">
<header>
<pre>ember.js globally available controllers like currentUser</pre>
</header>
<hr/>
<div>
<p>Signed in as {{controllers.currentUser.content}}</p>
<h2>All Users:</h2>
<ul>
{{#each user in one_list}}
<li> {{user}} </li>
{{/each}}
</ul>
</div>
<hr/>
<footer>
<a href="http://stackoverflow.com/questions/14388249/ember-js-globally-available-controllers-like-currentuser">Original StackOverflow Post</a>
</footer>
</script>
JavaScript
window.App = Ember.Application.create();
App.ApplicationController = Ember.Controller.extend({
needs: ['currentUser', 'users'],
one_list: (function() {
array = this.get('controllers.users.content');
array.push( this.get('controllers.currentUser.content') );
return array;
}).property('controllers.currentUser.content','controllers.users.content')
});
App.CurrentUserController = Ember.ObjectController.extend({
content: 'mike'
});
App.UsersController = Ember.ArrayController.extend({
content: ['mike', 'jen', 'sofia'],
init: function() {
var _self = this;
setTimeout(function(){
_self.content.pushObject('hank');
}, 2000);
}
});