samedi 23 juillet 2016

Ember setupController hook in route disconnects model from template

I am trying to set a controller property as soon as my login route is entered. At the moment, I am using method 1, which relies on init in the controller. It works fine, but my understanding is that it is better to use a setupController hook in the route. Ember data shows the record which has been created and the email and password fields update when you type.

I have tried to change the code, to use a setupController hook in the route (Method 2), rather that relying on init in the controller. With this method, the new record is created when entering the route, but email and password are undefined in Ember data, and don't update when typing.

Is there a way that I can still use setupController without disconnecting the model?

Method 1 - Working

routes/login.js

model: function() {
  return this.store.createRecord('authorisation');
},

controllers/login.js

setPreLoginMessage: function() {
  this.set('preLoginMessage', 'Please enter your username and password.'));
}.on('init'),

templates/login.hbs

 

Method 2 - Not working

routes/login.js

model: function() {
    return this.store.createRecord('authorisation');
  },

  setupController: function(controller, model) {
    controller.set('preLoginMessage', 'Enter your username and password'));
},

templates/login.hbs

 




Aucun commentaire:

Enregistrer un commentaire