Skip to content

Instantly share code, notes, and snippets.

@knownasilya
Created October 23, 2014 13:54
Show Gist options
  • Save knownasilya/024496388b8c849dec29 to your computer and use it in GitHub Desktop.
Save knownasilya/024496388b8c849dec29 to your computer and use it in GitHub Desktop.
var DynamicView = Ember.ContainerView.extend(Ember._Metamorph, {
childViews: [],
viewChanged: function () {
var viewName = this.get('viewName');
var view = this.container.lookup('view:' + viewName);
if (view) {
this.clear();
this.pushObject(view);
}
}.observes('viewName').on('init')
});
Ember.Handlebars.registerBoundHelper('dynamic-view', Ember.Handlebars.makeViewHelper(DynamicView));
@knownasilya
Copy link
Author

viewChanged doesn't fire after the initial init fire when using {{dynamic-view viewName=myView}}. But {{log myView}} works just fine.

This is using 1.7.

Note: I know Ember._Metamorph is private, but there is no good alternative. I'm assuming that's what has changed.

@knownasilya
Copy link
Author

Also, {{view}} doesn't work with dynamic view names: http://emberjs.jsbin.com/wifido/edit?html,js,output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment