Adam Krawesky
Adam Krawesky

Reputation: 1353

why is ember automatically passing an incorrect controller to a view instance?

i'm trying to add a view inside a template. this template defines a view called NewAssetLinkView. inside of it i'm adding TracksView. ember gives the exception :

Uncaught Error: assertion failed: an Ember.CollectionView's content must implement Ember.Array. You passed AssetLinksApp.NewAssetLinkController:ember538

it seems that the router is trying to automagically create NewAssetLinksController and apply it to TracksView, which is wrong. perhaps its doing this because TracksView is declared inside the NewAssetLinkView? (btw, NewAssetLinkController extends ObjectController)

i have a TracksController that TracksView should be using - how can i get the router to not try to automatically create and associate the wrong controller with TracksView?

<script type="text/x-handlebars" data-template-name="new_asset_link_view">
    .....
    {{view AssetLinksApp.TracksView}}
</script>

Upvotes: 2

Views: 1682

Answers (1)

Ryan
Ryan

Reputation: 3594

When you instantiate a view inside of a template the newly created view will be passed the controller of the view that created it. This is really useful because any view can access controller and does not need a binding to something like parentView.controller.

However, in your case you want to use a different controller. So you can pass in a controller binding with the {{view}} helper.

Try using

{{view AssetLinksApp.TracksView controller="AssetLinksApp.tracksController"}}

Upvotes: 5

Related Questions