Note that there are some explanatory texts on larger screens.

plurals
  1. POEmber.js setting application property on load
    primarykey
    data
    text
    <p>I'm trying to fetch the current logged in user via my REST API and then set it as a property of the ApplicationController. This is how I'm trying to do it:</p> <pre><code>App.ApplicationController = Ember.Controller.extend({ init: function() { this._super(); var self = this; App.User.findCurrent().then(function(user) { self.set('currentUser', user); }); } }); App.User = Ember.Object.extend({}); App.User.reopenClass({ findCurrent: function() { return $.getJSON('/api/v1/users/current').then( function(response) { return response.user; } ); } }); </code></pre> <p>When I check the Chrome network tab, I see there's a call to the API and the JSON is returned, but when I try to access e.g. <code>{{currentUser.name}}</code> in my application template (or a partial of it), it doesn't return the name. No errors are given as well.</p> <p>But in the application template it doesn't return it.</p> <p>What am I missing?</p> <p>Thanks!</p> <p><strong>Edit</strong></p> <p>When I create another controller, e.g. <code>HelpController</code> and visit <code>/help</code>, then <code>{{currentUser.name}}</code> does return the username:</p> <pre><code>App.HelpController = Ember.Controller.extend({ needs: ['application'], currentUser: Ember.computed.alias('controllers.application.currentUser') }); </code></pre> <p><strong>Edit 2</strong></p> <p>Sorry, I forgot to mention that I'm actually trying to use <code>{{currentUser.name}}</code> from a partial (<code>{{partial 'sidebar'}}</code>), but that shouldn't change anything, because that's the same scope, right?</p> <p><strong>Edit 3</strong></p> <p>I noticed something very strange. When I call <code>{{currentUser.name}}</code> in my application template (which is not what I want btw), then it also works in the <code>{{partial 'sidebar'}}</code>.</p> <p><strong>Edit 4</strong></p> <p>As per request:</p> <pre><code>DEBUG: Ember.VERSION : 1.0.0-rc.6 ember.js?body=1:361 DEBUG: Handlebars.VERSION : 1.0.0-rc.4 ember.js?body=1:361 DEBUG: jQuery.VERSION : 1.10.0 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload