I've been using requirejs and angularjs to load modules in my application, but I've run into an issue. I'm not sure how to load the controller after Angular has already been bootstrapped. Here is the code I have so far:
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
As a newbie to AngularJS, I'm really struggling with this issue. If anyone knows a way to load the MyCtrl controller after myApp has been bootstrapped, I would greatly appreciate any help.