Create/Assign controller while creating view


#1
var view = Ember.View.extend({

 templateName: 'some',
//action: 'save',
//click: function () { this.triggerAction(); },
init: function () {
 this._super();
this.set('controller', App.SomeController.create())
 }

});
view.create().appendTo("#divMain");

Here i am creating the view and appending to a div, however here i have to explicity set the controller this.set('controller', App.SomeController.create())

Is it possible to implicitly assign the controller while creating view?


#2

You can try to use ‘render’ helper in your template for rendering a view. In this case a controller will be implicitly assigned to a view.


#3

{{render}} or you can you can inject a view and assign it controller in an outlet by using the renderTemplate hook on the route.

If it’s an array, you can use the each handlebars helper like: {{#each contentArray itemController='someController'}}..{{/each}}