user1952811
user1952811

Reputation: 2458

Reset controller properties as you leave the route ember.js

I have some controller properties in the index controller. I am wondering how I can change the value of these properties when the user is changing the route. Since the index has an outlet, the index route properties are still present on a different route, which is what I want.

Basically when the route changes, I want to reset properties of the index controller. How do I do that?

Upvotes: 3

Views: 5428

Answers (1)

Kingpin2k
Kingpin2k

Reputation: 47367

from a different route:

var controller = this.controllerFor('index');
controller.set('foo', 'bar');

from a different controller:

App.FooController = Em.Object.extend({
  needs:'index',
  someFunc: function(){
    var controller = this.get('controllers.index');
    controller.set('foo', 'bar');
  }
});

on transition

App.IndexRoute = Em.Route.extend({
  actions: {
    willTransition: function(){
      this.controller.set('foo', 'bar');
    }
  }
});

Upvotes: 4

Related Questions