0
votes

I am trying to render a view dynamically in Ember.js

Resume.ItemView = Em.View.create({
  click: function(){
    var view = Em.View.create({
      templateName: 'my_exp'});
    view.append();
  },  
});

I have in /templates my_exp.hbs

But get

Uncaught Error: assertion failed: You specified the templateName my_exp for <Ember.View:ember261>, but it did not exist.

Is there a better approach for trying to do this? Can anyone suggest resources?

1
if you go to console and type Ember.TEMPLATES, do you see your template in the collection?MilkyWayJoe
yes: Ember.TEMPLATES; Object {application: function,... my_exp: function…}Dan Baker
That my friend... worked. Thank youDan Baker

1 Answers

3
votes

A recent update to Ember removed the defaultContainer for looking up templates. For people manually creating views this has created some issues.

To achieve what you want you need to use createChildView.

Resume.ItemView = Em.View.create({
  click: function(){
    var view = this.createChildView(Ember.View, {
      templateName: 'my_exp'
    });
    view.append();
  },  
});

(see fiddle)