Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Connect Outlet Ember 1.0 pre

##Connect Outlet

connectOutlet creates a new instance of a provided view class, wires it up to its associated controller, and assigns the new view to a property on the current controller.

The purpose of this method is to enable views that use outlets to quickly assign new views for a given outlet.

For example, an application view’s template may look like this:

<h1>My Blog</h1>

The view for this outlet is specified by assigning a view property to the application’s controller. The following code will assign a new App.PostsView to that outlet:


In general, you will also want to assign a controller to the newly created view. By convention, a controller named postsController will be assigned as the view’s controller.

In an application initialized using app.initialize(router), connectOutlet will look for postsController on the router. The initialization process will automatically create an instance of App.PostsController called postsController, so you don’t need to do anything beyond connectOutlet to assign your view and wire it up to its associated controller.

You can supply a content for the controller by supplying a final argument after the view class:

applicationController.connectOutlet(‘posts’, App.Post.find());

You can specify a particular outlet to use. For example, if your main template looks like:

<h1>My Blog</h1>
{{outlet master}}
{{outlet detail}}

You can assign an App.PostsView to the master outlet:

name: ‘posts’,
outletName: ‘master’,
context: App.Post.find()

You can write this as:

applicationController.connectOutlet(‘master’, ‘posts’, App.Post.find());

@param {String} outletName a name for the outlet to set @param {String} name a view/controller pair name @param {Object} context a context object to assign to the controller’s content property, if a controller can be found (optional)

Normalize arguments. Supported arguments:

name name, context outletName, name

outletName, name, context


The options hash has the following keys:

   name: the name of the controller and view
     to use. If this is passed, the name
     determines the view and controller.
   outletName: the name of the outlet to
     fill in. default: ‘view’
   viewClass: the class of the view to instantiate
   controller: the controller instance to pass
     to the view
   context: an object that should become the
     controller’s `content` and thus the
     template’s context.

This comment has been minimized.

Copy link

@achekh achekh commented Nov 2, 2012

There seems to be a bug with Ember 1.0 pre implementation.
It looks like the controller and context parameters don't work as expected.
Here are more details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.