我正在使用requirejs和angularjs在我的应用程序中加载模块。 我面临的问题是我不知道如何加载角度已被引导后的控制器。这里是我的代码:引导后的加载控制器angularjs
main.js:
require(['app', //all my scripts go here
function(){
angular.bootstrap(document, ['myApp']);
});
app.js:
define([], function(){
var myApp = angular.module('myApp', ['ngRoute']);
$routeProvider.
when('/home', {
templateUrl : 'partials/home.html',
controller : 'UserRegisterCtrl'
}).
otherwise({
redirectTo : '/home'
})
return myApp;
})
controller.js
define(['app'], function(app){
app.controller('MyCtrl', function($scope){});
})
myApp.html
body(ng-app)
<div ng-controller = 'MyCtrl'></div> <-- I can not put MyCtrl here
because I think the MyCtrl has been declared before myApp has been bootstrapped
因此,我真的需要知道是否有一种方法可以在引导myApp后加载MyCtrl控制器。我对Angularjs非常陌生。任何帮助将非常感激。
一个复杂的问题。看看几个努力,还有更多的野外......没有完成我认为:[angular-require-lazy](https://github.com/nikospara/require-lazy),[angularAMD ](https://github.com/marcoslin/angularAMD) –