Is there an opposite to setupController?

I install isActive in setupController:

 App.EntryRoute = Ember.Route.extend setupController: (controller) -> controller.set('isActive', true) 

I want to delete it when the route is changed.

What is the best way to do this? Are there hooks for when the controller is removed?

Edit: It seems I asked the wrong thing. I want to call this when the model is changed, which means that deactivate will not work, because it changes only after exiting the route.

+4
source share
3 answers

I want to delete it when the route is changed. What is the best way to do this?

You are probably looking for a deactivate hook route. Although not strictly the β€œopposite” of the setupController , deactivate will be called whenever the router leaves the route. Docs here: http://emberjs.com/api/classes/Ember.Route.html#method_deactivate

+2
source

Since @Mike Grassotti already mentioned deactivate , and his colleague activate is what you might need to solve your problem, this is what EntryRoute would look like:

 App.EntryRoute = Ember.Route.extend activate: () -> @controllerFor('index').set('isActive', true) deactivate: () -> @controllerFor('index').set('isActive', false) 

hope this helps

+1
source

To control the change in content , you can create a computed property that respects the "content" key or something that is fixed in the loaded model. Although I did not check it correctly, the code would be something like this:

 modelChanged: function() { //do something here }.observes('key_in_model') 

However, I do not understand that your code at some point changes the model loaded into your controller. Could you use this code to perform the transformations / expressions / etc that you need to do?

0
source

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


All Articles