我有一個簡單的控制器,它工作得很好:如何在運行中創建/實例化AngularJs控制器?
app.controller('IndexController', ['$scope', obj.indexPage]);
var obj = {};
obj.indexPage = function ($scope) { // do controller stuff };
我也有,我想用加載/創建一個事件函數/實例化這個控制器:
// some callback, doesn't really matter
app.onPage('index', function() {
// load and run controller logic in here
app.controller('IndexController', ['$scope', obj.indexPage]);
}, obj);
有一些問題像Argument 'IndexController' is not a function, got undefined
任何想法?
我的解決方案:
app.controller('IndexController', ['$scope', function ($scope) {
var obj = {};
obj.indexPage = function (data) {
// do controller stuff
};
app.onPage('index', function (data) {
obj.indexPage(data);
}, obj);
});
似乎不工作'參數'IndexPageController'不是一個函數,得到了undefined' – Patrioticcow