1

It's entirely possible that I'm not quite understanding the order of instantiation of controllers when a route is entered, but I'm attempting to get currentPath in beforeModel in my ApplicationRoute and struggling. The odd thing is when I log the route, I can see a property called controller in it...

enter image description here

beforeModel: function(transition) {

    console.log(this);
    console.log(this.controller); // undefined
    console.log(this.get('controller')); // undefined

    // this too
    console.log(this.controllerFor('application'));
    console.log(this.controllerFor('application').currentPath); // undefined
    console.log(this.controllerFor("application").get("currentPath")); // undefined

},

But this.controller is undefined. As you can see in the log output, currentPath is indeed set on that property, and that's what I want!

I noted that controller clearly isn't defined until after the router has instantiated the controller. So the documentation is somewhat clear in that in willTransition, this.controller is defined.

The controller property seems to get defined in setup so I'm super confused as to how I can see it in beforeModel. How can I get currentPath in beforeModel in ApplicationRoute?

typeoneerror
  • 55,990
  • 32
  • 132
  • 223

1 Answers1

0

Turns out that console.log with an object returns a reference to said object. So it's not a snapshot of the object at the time of the log.

This little trick got me the object in the state when logged:

console.log($.extend({}, this));
Community
  • 1
  • 1
typeoneerror
  • 55,990
  • 32
  • 132
  • 223