收到此错误......
Error: [ng:areq] Argument 'registerController' is not a function, got undefined
尝试转换到ui-router状态时...
.state('register', {
url: "/register",
templateUrl: "App/components/register/registerView.html",
data: { pageTitle: 'Register', specialClass: 'gray-bg' },
controller: "registerController",
resolve: { // Any property in resolve should return a promise and is executed before the view is loaded
loadMyCtrl: ['$ocLazyLoad', function ($ocLazyLoad) {
// you can lazy load files for an existing module
return $ocLazyLoad.load(['App/components/register/registerController.js']);
}]
}
})
检索并运行延迟加载的文件,此处仅供参考。
var app = angular.module('application')
function registerController($scope) {
$scope.test = "test";
};
app.controller('registerController', registerController);
当州试图解决
时抛出异常controller: "registerController",
属性。但是我知道延迟加载的代码已经在这一点上运行了" registerController"已注册为控制人。
答案 0 :(得分:0)
所以,事实证明你不能这样做。以上述方式注册控制器仅适用于引导程序。
但是如果你在config
中存储对$ controllerProvider寄存器函数的引用,你就可以这样做app.config(function ($controllerProvider) {
app.lazy = {
controller: $controllerProvider.register,
};
}
然后在你的控制器js中使用对寄存器功能的引用添加控制器..
var app = angular.module('application')
function registerController($scope) {
};
app.lazy.controller('registerController', ['$scope' ,registerController]);