Permalink
Browse files

Views should inherit controllers from their parent

  • Loading branch information...
Tom Dale
Tom Dale committed May 31, 2012
1 parent 43b99b1 commit ee46ed0a3bbde4f1b21e5b7d4a5550470a138a4e
Showing with 13 additions and 10 deletions.
  1. +13 −10 packages/ember-views/lib/views/view.js
@@ -492,7 +492,17 @@ Ember.View = Ember.Object.extend(Ember.Evented,
@type Object
*/
controller: null,
controller: Ember.computed(function(key, value) {
var parentView;
if (arguments.length === 2) {
return value;
} else {
parentView = get(this, 'parentView');
return parentView ? get(parentView, 'controller') : null;
}
}).property().cacheable(),
/**
A view may contain a layout. A layout is a regular template but
@@ -747,18 +757,11 @@ Ember.View = Ember.Object.extend(Ember.Evented,
}, '_parentView'),
cloneKeywords: function() {
var templateData = get(this, 'templateData'),
controller = get(this, 'controller');
var templateData = get(this, 'templateData');
var keywords = templateData ? Ember.copy(templateData.keywords) : {};
keywords.view = get(this, 'concreteView');
// If the view has a controller specified, make it available to the
// template. If not, pass along the parent template's controller,
// if it exists.
if (controller) {
keywords.controller = controller;
}
keywords.controller = get(this, 'controller');
return keywords;
},

1 comment on commit ee46ed0

@josepjaume

This comment has been minimized.

Show comment
Hide comment
@josepjaume

josepjaume May 31, 2012

Contributor

Awesome! I struggled with this problem yesterday. I ended up using this.get('context') but seemed inadequate.

Contributor

josepjaume commented on ee46ed0 May 31, 2012

Awesome! I struggled with this problem yesterday. I ended up using this.get('context') but seemed inadequate.

Please sign in to comment.