Transition to EmberJS route event

emberjs-1.0.0-RC-6.1

My controller:

Application.LoginController = Ember.Controller.extend({ loginFailed: false, isProcessing: false, isSlowConnection: false, timeout: null, login: function() { /* some code */ }, success: function() { this.reset(); }, failure: function() { this.reset(); }, reset: function() { clearTimeout(this.get("timeout")); this.setProperties({ isProcessing: false, isSlowConnection: false }); } }); 

My routing:

 Application.LoginRoute = Ember.Route.extend({ setupController: function(controller, model) { controller.reset(); }, events: { } }); 

When I first go to "/ login", setupController is called. However, I would like to use an event (such as a transition) to call controller.reset () every time the application goes to login.

With LOG_TRANSITIONS: true

I see "Switch to" login "," Switch to "anotherPage" on the console, so I would like to know if it is possible to get an event that triggers these logs in my router.

Like:

 Application.LoginRoute = Ember.Route.extend({ setupController: function(controller, model) { controller.reset(); }, events: { didTransition: function(reason) { controller.reset(); } } }); 
+4
source share
1 answer

I would like to know if it is possible to get an event that triggers these logs in my router.

You can connect to the activate and deactivate routes, and then call the controller methods, for example:

 Application.LoginRoute = Ember.Route.extend({ activate: function() { this.controllerFor('login').send('reset'); }, deactivate: function() { this.controllerFor('login').send('reset'); } }); 

Hope this helps.

+3
source

Source: https://habr.com/ru/post/1495541/


All Articles