I am trying to have angular and jquery loaded with requirejs. The best I can do is that in 50% of cases everything loads correctly, and the other half is a No Module: mainApp
I guess this breaks half the time based on the speed at which requirejs asynchronously loads scripts.
When it works, I see the test "Hello World" (although I see {{text}} flash before replacing, but I read how to fix it here). The rest of the time I get an error message and {{text}} just stays on the screen.
Github repo
Tree:
index.html - js - libs require.js - modules mainApp.js main.js
main.js
require.config({ paths: { 'jQuery': '//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min', 'angular': '//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular', }, shim: { 'angular' : {'exports' : 'angular'}, 'jQuery': {'exports' : 'jQuery'} } }); require(['jQuery', 'angular', 'modules/mainApp'] , function ($, angular, mainApp) { $(function () {
modules/mainApp.js
define(['angular'], function (angular) { return angular.module('mainApp' , []).controller('MainCtrl', ['$scope', function ($scope) { $scope.text = 'Hello World'; }]); });
Relevant index.html
<head> <script src="js/libs/require.js" data-main="js/main"></script> </head> <body> <div ng-app="mainApp"> <div ng-controller="MainCtrl"> {{text}} </div> </div> </body>
source share