EmberJS – sharing a controller / template for different routes

You were correct throughout.

And you can use the new controller and template in edit route also.

You have to do only two things.

First give the template name as new in the renderTemplate hook of edit route.

App.LocationsEditRoute = Ember.Route.extend({
  setupController: function(controller, model) {
    this.controllerFor('locations.new').setProperties({isNew:false,content:model});
  },
  renderTemplate: function() {
    this.render('locations/new')         
  }
});

As the new template is rendered the controller also will be newController, and you can have the action to point to an event in the newController.

If you want to change the title and button text, you can have them as computed properties observing isNew property.

Hope this helps.

P.S: Don’t forget to set the isNew property to true in the setupController of new route

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)