Reputation: 19979
I am calling an event like so:
{{#each}}
<div class='row'>{{name}} <a {{action showModal this}} href="#">Open modal</a>
{{/each}}
and have this route but NEED to set the model for the modal view but nothing seems to work. How can I get this to work?
App.ApplicationRoute = Ember.Route.extend({
events: {
showModal: function(obj) {
var v = this.container.lookup('view:modal');
// this.get('controller').set('model',obj); nope
v.appendTo(Emberjs1.rootElement);
}
}
});
Upvotes: 1
Views: 401
Reputation: 47367
You can set properties directly on the view and access them in your view's template using the view.property
var v = this.container.lookup('view:foo');
v.set('bar', 'hello');
v.appendTo(App.rootElement);
Then in the template it'd be
{{view.bar}}
http://emberjs.jsbin.com/qofoxazu/1/edit
If you really felt like create a controller/model you could get a controller, set the model on the controller, then set that model on your view.
var v = this.container.lookup('view:foo'),
controller = this.container.lookup('controller:foo');
controller.set('model', 'hello');
v.set('controller', controller);
v.appendTo(App.rootElement);
Then your controller will be in scope and you wouldn't have to use view
to access the properties.
http://emberjs.jsbin.com/qofoxazu/2/edit
Upvotes: 2