Is there a shorthand for the following code (i.e. calling controller attribute from the same named route)
self.controllerFor(self.routeName).get(‘myAttribute’)
I have already tried self.controller.get(‘myAttribute’)
Is there a shorthand for the following code (i.e. calling controller attribute from the same named route)
self.controllerFor(self.routeName).get(‘myAttribute’)
I have already tried self.controller.get(‘myAttribute’)
Within your route, you can do this.get('controller')
.
Thanks. But I get that as “undefined”
May I know where did you cal this.get(‘controller’) ?
Because, before calling this.get(‘controller’), the controller must be associated to the route. This happens in
setupController(controller, model) { //Your code }
Ember.Route.reopen({
getControllerAttr: function(controllerName, propertyName) {
return this.controllerFor(controllerName).get(propertyName);
},
getControllerAttr2: function(propertyName) {
return this.controllerFor(this.get('routeName')).get(propertyName);
}
});
I don’t write the setupController since it is the same route/controller & I do not have any additional custom code
@Sarath I did this in a route action.
But is it necessary to write setupController to get this shorthand to work ?