角控制器不加载使用OcLazyLoad和ngRoute [英] Angular controller not loading using OcLazyLoad and ngRoute
问题描述
我有一个应用程序,它具有最初的脚本加载的负载和名单还在不断增加作为发展下去。我想需要的时候为和包含控制器的延迟加载脚本。我使用OcLazyLoad与ngRoute沿着路由选择(我曾尝试这实际上有同样的最终结果UI的路线,但被造成其他应用的问题)。延迟加载和路由工作正常,脚本和意见在需要时才会加载,但问题是该控制器没有被加载(参数caseReviewController'是不是),所以它仿佛控制器不存在。
I have an app that which has a load of scripts loading initially and the list is growing as development goes on. I want to lazy load scripts which contain controllers as and when needed. I am using OcLazyLoad along with ngRoute for the routing option (i did try ui-route which actually had the same end result but was causing other app issues). The lazy load and routing is working fine, scripts and views are only loaded when needed, but the issue is the controller is not being loaded (Argument 'caseReviewController' is not) so it's as though the controller does not exist.
下面是什么,我有我的app.js文件...
Here is a simple version of what I have in my app.js file...
var app = angular.module('dashboard', ['oc.lazyLoad', 'ngRoute', 'LocalStorageModule']);
app.config(function ($ocLazyLoadProvider, $routeProvider, localStorageServiceProvider) {
$ocLazyLoadProvider.config({
loadedModules: ['dashboard'], modules: [
{
name: 'caseReview',
files: ['js/controllers/case-review.js']
}
]
});
$routeProvider
//other routes here...
.when('/case-review', {
templateUrl: 'views/case-review.html',
controller: 'caseReviewController',
resolve: {
loadModule: ['$ocLazyLoad', function ($ocLazyLoad) {
return $ocLazyLoad.load('caseReview');
}]
}
})
});
在单独的情况下,review.js文件我有一个简单的控制器
In the seperate case-review.js file I have a simple controller
app.controller('caseReviewController', function($scope, localStorageService, $route){
//do stuff
});
这控制器没有被发现或执行,但视图和js文件正在被延迟加载的预期。任何帮助将是巨大的。
This controller is not being found or executed but the view and js file are being lazy loaded as expected. Any help would be great.
感谢。
推荐答案
在您的单独的案例review.js
,你必须得到应用
。
In your separate case-review.js
, you must get the reference of app
.
angular.module('dashboard').controller('caseReviewController', function($scope, localStorageService, $route){
//do stuff
});
正如你所提到的它在单独的文件,它可能不知道有关应用
变量。这是更好地得到单独的文件中的角模块的参考。
As you've mentioned it's in separate file, it may not know about the app
variable. It's better to get the reference of the angular module in the separate file.
这必须解决您的问题。
这篇关于角控制器不加载使用OcLazyLoad和ngRoute的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!