0

While connectOutlet("basename") automatically creates an instance of BasenameController, I was wondering if there's a way to do the same using the {{view}}-helper.

I have tried several things I've seen in examples, but non of them seem to work:

{{view controllerBinding=App.BasenameController}}

{{view controllerBinding=App.basenameController}}

{{view controllerBinding="App.BasenameController"}}

{{view controllerBinding="App.basenameController"}}

I have also tried to do the same using controller instead of controllerBinding, unfortunately without success, and I was also unable to find out where exactly the difference is between the two of them.

Does anybody know how to achieve my goal?

stakx - no longer contributing
  • 83,039
  • 20
  • 168
  • 268
kraftwer1
  • 5,253
  • 10
  • 36
  • 54
  • 1
    It's not correct that `connectOutlet("basename")` creates an instance of *BasenameController*. It actually looks up `basenameController` on the `controllers` collection of the controller you are calling `connectOutlet` on. Typically, the `controllers` property will be pointing to the router. So what you're actually getting is the instance of *BasenameController* that the router has access to and was created once at app initialization time. – Luke Melia Nov 05 '12 at 06:25
  • I Found this answer to be more than helpful http://stackoverflow.com/questions/11318572/right-way-to-do-navigation-with-ember – tastybytes Dec 07 '12 at 14:18

1 Answers1

1

You probably want to use an outlet. The connectOutlet/outlet functions are meant for rending other controller/view pairs.

Lets say we have a person view, but inside that view we want to have another controller/view pair. For this, we need to use a named outlet, our template would look like this.

Person View!
{{name}} = the person's name!
{{controller}} = PersonController!
{{outlet other}} = our outlet

Then inside the router when you want to attach another controller/view to that outlet you can simple use connectOutlet on the personController.

router.get('personController').connectOutlet('other', 'other');

That will wire OtherController and OtherView together and display them in your template. The first param is the outlet name, the 2nd is the controller/view.

This allows you to easily swap different controllers and views onto that outlet. For example, using a different connectOutlet api, we could

router.get('personController').connectOutlet({
 outletName: 'other',
 controller: router.get('carsController'),
 viewClass: App.CarsView
});

...

Btw, to answer you original question. You can get access to other controllers from your view by doing this: {{view controllerBinding="controller.target.otherController"}}. Every controller will have a target property that points back to the router. However, I do not recommend using this code. It's brittle, hard to test, hard to debug, and will come back and bite you in the future.

Ryan
  • 3,594
  • 1
  • 24
  • 23