It’s possible to access the controller as a property on a route but it seems there’s no straight way to go from the controller back to the route. Let’s say a property on the controller is changed and I’d like to have the route to fetch some new data. It seems a pretty common pattern.
The controller shouldn’t be coupled to the route, like the views shouldn’t be coupled to controllers. If you need the route to load data, use send
which will bubble an event through the route hierarchy.
http://emberjs.com/api/classes/Ember.Controller.html#method_send
Thanks! I know about the send
mechanism. Well, I thought the controller being a property on the route is already coupled to the route. How would I know if any property is explicitly not observable on a route or any other type of objects in Ember?
I’d imagine the code in a route to be like this:
ApplicationRoute = Ember.Route.extend({
appPropertyChanged: (function() {
return console.log('routeNameChanged from ApplicationRoute');
}).observes(['controller.someProperty'])
});
Sorry, I misunderstood your original question. I thought you wanted to access the route from the controller.
You can setup observers from your Route on to your controller like this: