0

For a route /dashboard I have, DashboardController & 2 different named outlets in DashboardView.

connectOutlet of /dashboard Route looks like following

connectOutlets: function(router) {
    var appController = router.get('applicationController');
    appController.connectOutlet('dashboard', {});

    var dashboardController = router.get('dashboardController');
    dashboardController.connectOutlet({
        name: 'dashProjects',
        outletName: 'dashProjects',
        context: App.Project.find()
    });                                     
    dashboardController.connectOutlet({
        name: 'projectSummary',
        outletName: 'projectSummary'
    }); 
}

Now on click on item(Project) in DashProjectsView, ProjectSummaryView should be updated.

What should be ideal way of sharing an object (in this case Project) between controllers.

One way of doing is creating an shared global object in App.currentProject, but it defeats the purpose.

I think, DashboardController should hold to an object and DashProjects and ProjectSummary should be accessing it. Any guidance/pointers are welcome.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Nachiket
  • 6,021
  • 6
  • 41
  • 47

2 Answers2

2

Perhaps you could have a look at https://github.com/emberjs/ember.js/blob/master/packages/ember-views/lib/system/controller.js#L173, and connect dashProjectsController to projectSummaryController.

sly7_7
  • 11,961
  • 3
  • 40
  • 54
  • Thanks for the link. But where connectController should be written? In connectOutlet? For example I have /dashboard and /statistics pages where I need same controller. One way of doing is, I write connect connectController on both route's connectOutlets. Is there any other place or way? – Nachiket Sep 20 '12 at 16:41
  • I think you can do it when application is ready, defining the `App.ready` function. see http://www.lukemelia.com/blog/archives/2012/08/23/architecting-ember-js-apps/ slide 31 for an example – sly7_7 Sep 20 '12 at 16:58
1
connectOutlets: function() {
    router.get('dashboardController').connectControllers('projectSummary')
    ... Other code you might have here ...
}

App.DashboardController: Ember.Controller.extend({
    projectSummaryController: null,
    ... Other code in your controller ...
}

You can then get hold of your projectSummaryController from your dashboardController.

Joachim H. Skeie
  • 1,893
  • 17
  • 27