mercredi 5 août 2015

Ember setupController and transient controllers

I'm trying to use setupController method to pass some data to the controller from the route and it only works if the controller is a singleton.

The setupController method is called in both situations but the variables are only set on the controller if it's a singleton.

How can I pass data from a route to a transient controller?

Here's a twiddle: http://ift.tt/1KRpFSd

Uncomment/comment the following line to toggle between singleton/transient: //application.register('controller:application', 'ApplicationController', { singleton: false });

I have not been able to find any information about whether or not this should work.

controllers/application.js:

import Ember from 'ember';

export default Ember.Controller.extend({
  appName:'Ember Twiddle'
});

initializers/application.js:

export function initialize(container, application) {
 //application.register('controller:application', 'ApplicationController', { singleton: false });
}

export default {
  name: 'application-init',
  initialize: initialize
};

routes/application.js:

import Ember from 'ember';

export default Ember.Route.extend({
  setupController: function(controller,model) {
    this._super(controller,model);
    controller.var1 = "Variable 1";
  }
});

templates/application.hbs:

<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{var1}}
<br>





Aucun commentaire:

Enregistrer un commentaire