Needs with nested controller


#1

I need to access the data from AccountQueueController from a child controller. This used to work:

needs['accountQueue']
...
this.get('controllers.accountQueue.myProperty')

But now, as of Ember 1.11, this doesn’t work. I get:

needs [ controller:accountQueue ] but it could not be found

After fiddling around with it a bit, I found this to stop the above error:

needs['account/queue']

but now I can’t access the property I need using this.get(‘controllers…’). I’ve tried every possible casing I can think of and it always gives me some form of:

Uncaught ReferenceError: <versace@controller:account/queue-item::ember1124>#needs does not include `accountQueue`.

An additional bit of context - This version bump is part of switching my project from rails to Ember CLI, which for the record is a huge pain. I don’t know if the Ember CLI shift has anything to do with this, though it really shouldn’t.

As a sidenote, for a platform that supposedly is opinionated, the syntax for concatenation of names is incredibly arbitrary. I have seen all the following used for referencing AccountQueue, depending on context/Ember version:

AccountQueue
accountQueue 
account-queue
account_queue
account.queue
account/queue

It is super frustrating, especially when all the guides with examples have a habit of using single worded class names. You would think this question about needs would be answered somewhere, but I simply can’t find an answer, or even an example, of a two worded class using needs “properly”.


#2

UPDATE - This works:

needs['account/queue']
...
this.get('controllers.account/queue.model.myProperty')

That’s pretty hideous, and definitely not formatted like anything I’ve seen in any doc. Is this the new preferred way?


#3

It is a little confusing entering from a non-CLI world. The reason it’s different here is because CLI has it’s own ES6 semantics-based resolver.

There’s some documentation on nested directories in the CLI project: http://www.ember-cli.com/#nested-directories


#4

Get the Ember Inspector browser extension. From it you can click on “Routes” and it will show you route names along with their associated controller names (there are some situations - like resources instead of routes - which will not give the correct names, but for the most part it’s the name you want).


#5

I’m not sure this will help you but you may try the new inject syntax in combination with @uberclops’ name suggestion. In past I’ve had issues with the get part after calling needs, it’s been easier with the new syntax.


#6

With new inject syntax:

accountQueueController: Ember.inject.controller('account/queue'),
...
this.get('accountQueueController.model.myProperty')

#7

This is much nicer. Thanks for the suggestion.