Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Im trying to add AngularJS to my web application which already makes use of RequireJS. I have followed a couple of YouTube and web tutorials but for some reason, when loading my test page, i am seeing:

1) Error: [$injector:modulerr] http://errors.angularjs.org/1.2.16/$injector/modulerr?p0=MyApp&p1=%5B%.....

2) TypeError: Modernizr is undefined
if (!Modernizr.history) {

3) For some reason jQuery has stopped working too.

Here's my tree:

resources
   - CSS
   - js
        - controllers
             - MainController.js
        - libs
             - angular.js
             - jquery.js
             - require.js
             - mondernizr.js
             ......
             ......
             ......
        main.js
        app.js
pages
        test.html

main.js

(function(require) {
'use strict';

require.config({
    baseUrl: '/resources/js',
    paths: {
        'jquery'    : 'libs/jquery',
        'angular'   : 'libs/angular',
        'router'    : 'libs/page',
        'history'   : 'libs/history.iegte8',
        'event'     : 'libs/eventemitter2'
    },
    shim: {
        'zepto'     : { exports: '$' },
        'angular'   : { exports : 'angular' },
        'router'    : { exports: 'page'}
    }
});



require([
    'controllers/MainController'
]);

})(this.require);

app.js

define(['angular'], function(angular) {
return angular.module('MyApp', []);
})

MainController.js

require(['app'], function(app) {
    app.controller('MainController', function() {
        this.message = "Hello World";
    })
});

test.html

<!DOCTYPE html>
<html ng-app="MyApp">
<head>
    <title>AngularJS Test</title>
</head>
    <body>        
        <div ng-controller="MainController as main">
            {{ main.message }}
        </div>    

        <script src="/resources/js/libs/require.js" data-main="/resources/js/main"></script>

    </body>
</html>

Using AngularJS v1.2.16

Any help appreciated.

UPDATE ******************************************

Have added <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular-route.js"></script> to my test.html page and the Error: [$injector... error has disappeared.

Only error now showing is:

TypeError: Modernizr is undefined

if (!Modernizr.history) {

Followed advice on here: http://activeintelligence.org/blog/archive/error-injectornomod-module-ngroute-is-not-available/

share|improve this question

1 Answer 1

I went over to Modernizr's site and checked the code. I see that it does not call define to define itself as a module so Modernizr is not AMD-compliant and you need a shim for it to tell RequireJS what the module value should be:

shim: {
    ...
    modernizr: { exports: 'Modernizr' }
}
share|improve this answer
    
added your suggestion above, still getting the error. –  Oam Psy Apr 11 '14 at 8:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.