I am using AngularJS with RequireJS.
NEW QUESTION: RequireJS does not load any controllers. I am using this tutorial.
OLD QUESTION: RequireJS loads the main.js file, the bootstrap.min.js file and jQuery. This works good. But it does not load angular for some reason.
I am using chrome, and in the developer tools tab "network" there are only the 3 files mentioned above loaded.
console.log(typeof angular); equals to undefined. ( I have tried that in the developer console )
There is no error message shown in the console!
SOLUTION: I fixed it by adding 'angular' to the deps array.
My main.js code is:
// Require JS Configuration
require.config({ // Code format changed
// alias library paths
paths: {
'jquery': '../bower_components/jquery/dist/jquery.min',
'domReady': '../bower_components/requirejs-domready/domReady',
'angular': '../bower_components/angular/angular.min',
'angular-route': '../bower_components/angular-route/angular-route.min',
'ngFx': '../bower_components/ngFx/dist/ngFx.min',
'angular-ui-router': '../bower_components/angular-ui-router/release/angular-ui-router.min',
'bootstrap': '../bower_components/bootstrap/dist/js/bootstrap.min'
},
// angular does not support AMD out of the box, put it in a shim
shim: {
'angular': {
exports: 'angular'
},
'angular-route': {
deps: [ "angular" ]
},
'ngFx': {
deps: [ "angular" ]
},
'angular-ui-router': {
deps: [ "angular" ]
},
'bootstrap': {
deps: [ "jquery" ]
}
},
// Kick start application
deps: [
'./bootstrap',
'domReady',
'angular',
'angular-route',
'ngFx',
'angular-ui-router',
'bootstrap'
]
});
My bootstrap.js file:
define([
'require',
'angular',
'app',
'routes'
], function (require, ng) {
'use strict';
require(['domReady!'], function (document) {
ng.bootstrap(document, ['app']);
});
});
My app.js file:
define([
'angular',
'./controllers/index',
'./directives/index',
'./filters/index',
'./services/index'
], function (ng) {
'use strict';
return ng.module('app', [
'app.services',
'app.controllers',
'app.filters',
'app.directives',
'ngFx',
'ngRoute'
]).config(function ($urlRouterProvider) {
$urlRouterProvider.otherwise('/');
});
});
Folder structure:
angular
controllers
index.js
menu.js
module.js
directives
filters
services
app.js
bootstrap.js
main.js
routes.js
bower_components
...
Thank you for your help! :-)
'angular'intodepsarray in after'./bootstrap'exportsproperties for Angular. The only one you should need is for'angular', get rid of the rest.