I'm assuming your main.js
file is what you give to the data-main
attribute on the <script>
tag that loads RequireJS or that it is the main entry point of your application. Change main.js
to this:
require(['common'], function (common) {
require(['app']);
});
And create an app.js
module in a location where your code can readily load it:
define(['angularAMD'], function (angularAMD) {
var app = angular.module("app", []);
app.controller("testCtrl", function ($scope) {
$scope.message = "udało się!";
});
angularAMD.bootstrap(app);
return app;
});
Anything that needs access to the value of app
you create in this module can just require the app
module.
The code you have in the question defines a module but it does so asynchronously. By the time the call to define
happens, RequireJS has already finished loading main
. As far as it is concerned, main
is done. So what name should it give to the defined module?