ken
ken

Reputation: 9013

Ember "needs" ObjectController seems inaccessible

I have the following router in Ember:

  this.resource('clients', function() {
      this.route('new');
      this.route('client', { path: '/:id' }, function() {
        this.route('profile');
        this.route('sessions');
        this.route('payments');
      });   
  });

From within the clients.client.payments route I'd like to be able to access the client information from the parent controller clients.client but I'm struggling to find a way to do this. Currently from within the clients.client.payments controller I have:

needs: ['clients'],
client: computed.alias('controllers.clients'),

This works fine to connect to the array of client records but if I instead use:

needs: ['client'],
client: computed.alias('controllers.client'),

I get an error saying that it can not find the controller. I am now considering changing 'client' from a route to a resource (with the hope that this will resolve my problem) but is there really no way to achieve the results I'm looking for as-is?


based on on suggestion to try "clientsClient" in needs I have added the following to the clients.client.payments controller:

needs: ['clientsClient']

I also tried the more explicit:

needs: ['controller:clientsClient']

but in both cases I get the following error:

error

Very oddly recursive. I add "a" and it errors out saying it needs "a".

Note: the clients.client controller is defined explicitly as suggested


It was also suggested that dot notation (aka, needs: ['clients.client']) would be the way to go ... I actually tried that earlier as that was my first thought too but that results in a clearer error message:

needs must not specify dependencies with periods in their names (controller:clients.client)

Upvotes: 1

Views: 92

Answers (1)

Miguel
Miguel

Reputation: 20633

use forward slashes

needs: ['clients', 'clients/client'],
client: computed.alias('controllers.clients/client'),

Upvotes: 1

Related Questions