Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an opposite of setupController?

Tags:

ember.js

I am setting isActive in setupController:

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

I would like to remove it when the route is changed.

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

Edit: It seems I asked the wrong thing. I want to trigger this when the model is changed, meaning deactivate will not work, as it is only changed when you leave the route.

like image 228
jsteiner Avatar asked Oct 21 '22 10:10

jsteiner


2 Answers

I would like to remove it when the route is changed. What is the best way to do this?

Probably what you are looking for is the route's deactivate hook. While not strictly "the opposite" of setupController, deactivate will be called whenever the router exits the route. Docs here: http://emberjs.com/api/classes/Ember.Route.html#method_deactivate

like image 118
Mike Grassotti Avatar answered Oct 25 '22 18:10

Mike Grassotti


As @Mike Grassotti already mentioned deactivate and his counterpart activate are what you might need to solve your problem, this is how you EntryRoute could look like:

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

  deactivate: () ->
    @controllerFor('index').set('isActive', false)

hope it helps

like image 26
intuitivepixel Avatar answered Oct 25 '22 19:10

intuitivepixel