mardi 14 avril 2015

EmberJS - Calling a controller method within a routes setupController

I have a controller with a few methods attached to it. I have a relevant route. I added the methods inside the controller so that they can be re-used in a few other places. These methods retrieve some data from the server. Inside the setupController of the route, I'm calling these methods and everything works as expected.


But once I concatenate the files, Ember throws an error saying the method I'm trying to call is undefined. I use grunt-contrib-concat plugin but also tried changing it to use uglify. Still the same issue. I don't think there is anything wrong with the concatenation as it always worked previously. However, I never used the setupController before other than to set properties. Added the sample code below. Any help is appreciated.



/* Ember 1.10.0 Debug version */

/* Route */
App.DashboardRoute = Ember.Route.extend({
model: function() { return []; },
setupController: function(controller, model) {
this._super(controller, model);

/* Setting values on the controller works */
controller.set('currentDate', new Date());

/* Calling a method works normally but throws error when minified */
/* Error: dashboard undefined is not a function */
controller.addNumbers();
}
});

/* Controller */
App.DashboardController = Ember.ArrayController.extend({
currentDate: null,
addNumbers: function() {
return 1 + 2;
}
});




Aucun commentaire:

Enregistrer un commentaire