我为此使用RequireJS。并且在供应商,说lazyProvider:
在你懒的提供商...
this.resolve = function(controller){
return { myCtrl: ['$q',function ($q){
var defer = $q.defer();
require(['/app/controllers/'+controller,'myApp'],function(ctrl,myApp){
myApp.register.controller(controller,ctrl);
defer.resolve();
}
return defer.promise;
}]
};
};
在UI路由器resolve:
财产做:
resolve: lazyProvider.resolve('myCtrl');
你需要公开提供商在你的应用程序寄存器,以便以后可以注册它们,如:
myApp.config(function($urlRouterProvider, $stateProvider,
$controllerProvider, $compileProvider, $filterProvider,$provide){
//If your myApp isn't already a module...
define('myApp',[],function(){return myApp});
myApp.register = {
controller: $controllerProvider.register,
directive: $compileProvider.directive,
filter: $filterProvider.register,
factory: $provide.factory,
service: $provide.service,
constant: $provide.constant
}
而且你的控制器:
define(['/dependencies'],function(deps){
function MyCtrl($scope){...}
return MyCtrl;
}
这基本上是什么丹Wahlin共用here
有没有机会获得GitHub示例?在这一段时间里,遇到了各种各样的问题。 – mbursill
嘿,对不起,我没有时间。基本上,我实现它类似于答案中链接的博客文章。你有什么特别的问题? – calebboyd
这让我的大脑受伤,任何人都有一个真实世界的例子? – bryan