I am trying to load the dependencies for various angular modules using require.js. After configuring the dependencies in dependencies.js file, I get an error while loading the application which states "Module not available". I tried 2 variations of the file given below and the application fails on both the instances :
Variation 1 - Dependencies.js
require.config({
paths: {
angular: '../lib/dependencies/bower_components/angular/angular',
angularRoute: '../lib/dependencies/bower_components/angular-route/angular-route',
angularMessages: '../lib/dependencies/bower_components/angular-messages/angular-messages',
lodash: "../lib/dependencies/bower_components/lodash/dist/lodash",
jQuery: "../script/datetimepicker/jquery.min", // needed only by the date time picker
datetimepicker: '../script/datetimepicker/jquery.datetimepicker',
underscore: '../lib/dependencies/bower_components/underscore/underscore',
frontendServices: 'frontend-services',
myApp: "test-app"
},
shim: {
jQuery: {
exports: "jQuery"
},
angular: {
exports: "angular"
},
angularRoute: {
exports: "ngRoute"
},
angularRoute: {
deps: ['angular']
},
underscore: {
exports: "_"
},
underscore: {
deps: ['jQuery']
},
datetimepicker: {
deps: ['jQuery']
},
angularMessages: {
deps: ['angular']
},
frontendServices: {
deps: ['angular', 'lodash']
},
myApp: {
deps: [ 'lodash', 'angular', 'angularMessages', 'frontendServices', 'underscore']
}
}
});
require(['myApp'], function () {
angular.bootstrap(document.getElementById('myApp'), ['myApp']);
});
Variation 2 - Dependencies.js
require.config({
paths: {
angular: '../lib/dependencies/bower_components/angular/angular',
angularRoute: '../lib/dependencies/bower_components/angular-route/angular-route',
angularMessages: '../lib/dependencies/bower_components/angular-messages/angular-messages',
lodash: "../lib/dependencies/bower_components/lodash/dist/lodash",
jQuery: "../script/datetimepicker/jquery.min", // needed only by the date time picker
datetimepicker: '../script/datetimepicker/jquery.datetimepicker',
underscore: '../lib/dependencies/bower_components/underscore/underscore',
frontendServices: 'frontend-services',
myApp: "test-app"
},
shim: {
jQuery: {
exports: "jQuery"
},
angular: {
exports: "angular"
},
angularRoute: {
exports: "ngRoute"
},
angularRoute: {
deps: ['angular']
},
underscore: {
deps: ['jQuery']
},
datetimepicker: {
deps: ['jQuery']
},
angularMessages: {
deps: ['angular']
},
frontendServices: {
deps: ['angular', 'lodash']
},
myApp: {
deps: [ 'lodash', 'angular', 'angularMessages', 'frontendServices', 'underscore']
}
}});
require(['myApp'], function () {
angular.bootstrap(document.getElementById('myApp'), ['myApp']);
});
My controller file :
angular.module('myApp', [ 'frontendServices', 'underscore', 'angularRoute']).controller(
'TableCtrl',
[ '$http',
'$scope',
function($scope, $timeout) {
// contents
} ]);
After loading the application I get the errors like :
Error: [$injector:nomod] Module 'underscore' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. http://errors.angularjs.org/1.3.8/$injector/nomod?p0=underscore
Can anybody help provide me the correct way to configure underscore and ngRoute using require.js????