I have a question about Ember routing and controllers. I've just written a small App to get familiar with the new router. Therefore I've built a button that transitions to another state by clicking on it.
App.PostsView = Em.View.extend({
click: function() {
var router;
this.get('controller').transitionTo('about');
}
});
My question now is: what does the get
method return?. Obviously an instance of the PostController
but on the one hand the controller doesn't have a transitionTo()
method and on the other hand that would not make any sense.
this.get('foo')
returns a property of your Ember object. Since Views can have a "controller" property, this.get('controller')
returns the controller bound to your view's controller property (by default the postsController).
this.get('controller').transitionTo()
works because as sly7_7 mentioned, transitionTo()
is also defined on the controller and delegates to the router. Note, it's probably going to be deprecated and one should use
this.get('controller').transitionToRoute('about');
instead.