Let’s say I initiate a controller:
App.pageController = Ember.Controller.create({
pageNumber: '12',
})
And its corresponding view:
App.pageView = Ember.View.create({
templateName: 'page-template',
}).append();
And now its template:
<script type="text/x-handlebars" data-template-name = 'page-template'>
<div class = 'page-background'>
page: {{ pageNumber }}
</div>
</script>
I intend for pageController to provide the rendering context for pageView, however I do not know how to explicitly provide the instructions for this, and as a result pageNumber is not rendered.
I could go around this by putting a pageNumberBinding in pageView:
App.pageView = Ember.View.create({
templateName: 'page-template',
pageNumberBinding: 'App.pageController.pageNumber',
}).append();
And rewrite the template as follows
page: {{ pageNumber contextBinding="this" }}
But how would you do it the other way?
By setting the
controllerproperty on the view, the view will forward the properties it doesn’t know about to the controller.So, using your example, you could do:
Check out the Ember docs for Ember.View, and the introduction on their site.