0
我有一個控制器與幾個方法連接到它。我有一個相關的路線。我在控制器中添加了方法,以便它們可以在其他幾個地方重新使用。這些方法從服務器檢索一些數據。在路由的setupController裏面,我打電話給這些方法,一切都按預期工作。EmberJS - 調用路由中的控制器方法setupController
但是,一旦我連接的文件,Ember拋出一個錯誤,說我想要調用的方法是未定義的。我使用grunt-contrib-concat插件,但也嘗試將其更改爲使用uglify。仍然是同樣的問題。我不認爲串聯有什麼問題,因爲它以前一直都有效。但是,除了設置屬性之外,我從未使用setupController。在下面添加了示例代碼。任何幫助表示讚賞。
/* 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;
}
});