Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In Ember, for controllers to require other controllers, you need to use the <code>needs</code> property. This is always changing in Ember: in previous versions it was the responsibility of the router with <code>this.controllerFor</code>, and with even older versions, the approach was more akin to the approach you appear to be attempting to take. However, the final approach has long since been deprecated, and instances of controllers/models/views are no longer held on <code>App</code> directly, only their <strong>object</strong> representations.</p> <p>To dive straight in with the <code>need</code>s, you need to tell your <code>App.StarredCampaignsController</code> controller that it requires the <code>App.CampaignsIndexController</code> like so:</p> <pre><code>App.StarredCampaignsController = Em.ArrayController.extend({ content: [], needs: ['campaigns_index'] }); </code></pre> <p>You now have access to the <code>App.CampaignsIndexController</code> controller in your starred campaigns view: <code>{{controllers.campaigns_index}}</code>.</p> <p><em>See simple JSFiddle: <a href="http://jsfiddle.net/AGJfB/" rel="nofollow">http://jsfiddle.net/AGJfB/</a></em></p> <p>The reason why yours isn't working is because you've reference the object of the controller, as opposed to its instance:</p> <pre><code>Ember.Binding.oneWay('App.CampaignsIndexController.content') </code></pre> <p>Whilst you have an <code>App.CampaignsIndexController</code> on <code>App</code>, that's its object. Ember will create the instance for you when you access it through any of the Ember ways (<code>this.controllerFor</code>, <code>needs</code>, navigating to it via the URL, etc...).</p> <p>In days gone by we could use:</p> <pre><code>Ember.Binding.oneWay('App.campaignsIndexController.content') </code></pre> <p>However, that's such a bad way to do things, because you're referencing an absolute path to the controller. Ever since Ember pre 1, I've never had to use <code>Ember.Binding.oneWay</code>, but there still will be cases where you need it. When you find yourself using it though, it's probably wise to ask yourself if it's necessary, and whether there's a better way to do it.</p> <p>I hope I've explained myself well. Please feel free to ask any questions!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload