willmcneilly
willmcneilly

Reputation: 658

Running Code in active Controller after transitionToRoute

I'm getting to know emberjs by building a simple pomodoro app. My problem is running code in the newly active controller after a transitionToRoute has occured.

Here's where I create a new Pomodoro record:

App.PomodorosNewController = Ember.ObjectController.extend({
  createPomodoro: function() {
    this.get('model.transaction').commit();
    this.transitionToRoute('pomodoros.pomodoro', this.get('model'));
  },
});

As you can see I create the record, then transition to the newly created record's view. Which is using this controller:

App.PomodorosPomodoroController = Ember.ObjectController.extend({});

My question is how do I run code in this controller after the transition has occured? This there a way I can detect a transitionToRoute in the receiving controller?

Upvotes: 1

Views: 489

Answers (1)

ianpetzer
ianpetzer

Reputation: 1838

You can implement the setupController function in your PomodorosPomodoroRoute

This will be invoked every time you transition to that route and can be used to set up your controller and anything you need for the view.

App.PomodorosPomodoroRoute = Ember.Route.extend({

  setupController: function(controller, model) {
    this._super.apply(this, arguments);
    //implement your code here
  }


});

Upvotes: 2

Related Questions