Reputation: 497
In the AuthController of my Ember app, I set a currentUser that I can fetch from within the AuthController with
this.get('currentUser');
from within the AuthController. In another controller, I use needs: ['auth']
so that I can fetch the currentUser variable from the auth controller, but it's not working. How would I do that?
App.BlobController = Ember.ObjectController.extend({
needs: ['auth'],
actions: {
doSomething: function() {
var user;
user = this.get('currentUser'); /// not working
$.post(".....
Update
Following the instructions in the Ember docs for managing dependencies between controllers http://emberjs.com/guides/controllers/dependencies-between-controllers/, I also tried to do controllers.auth.get('currentUser');
but it didn't work
doSomething: function() {
var user;
user = controllers.auth.get('currentUser'); /// not working
$.post(".....
Upvotes: 0
Views: 289
Reputation: 23322
The way it works would be to do it like the following:
App.BlobController = Ember.ObjectController.extend({
needs: ['auth'],
actions: {
doSomething: function() {
var user;
user = this.get('controllers.auth.currentUser');
$.post("...
Or more clean declaring a computed alias on the BlobController
which refers to the AuthController
currentUser
property:
App.BlobController = Ember.ObjectController.extend({
needs: ['auth'],
currentUser: Ember.computed.alias('controllers.auth.currentUser'),
actions: {
doSomething: function() {
var user;
user = this.get('currentUser');
$.post("...
Hope it helps.
Upvotes: 4