1

I am trying to create a new angular project with requireJS.

here is my index.html:

<!doctype html>

<html ng-app="MainApp">

<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <script data-main="js/requirejs.config.js" src="common/lib/requirejs/require.js"></script>

    <title>{{'TITLE' | translate}}</title>

    <link rel="stylesheet" href="common/lib/bootstrap-3.1.1-dist/css/bootstrap.css">

    <link rel="stylesheet" href="css/app.css">
</head>

<body ng-controller="MainCtrl" ng-cloak class="ng-cloak">
    <button type="button" class="btn btn-default btn-lg">
        <span class="glyphicon glyphicon-star"></span>{{'HELLO' | translate}}
    </button>
</body>

</html>

and here is my requirejs.config.js:

require.config({
baseUrl: 'common',
paths: {
    angular         : 'lib/angular-1.2.19/angular',
    jquery          : 'lib/jquery/jquery-2.1.1',
    uibootstrap     : 'lib/ui-bootstrap-0.11.0/ui-bootstrap-tpls-0.11.0',
    bootstrap       : 'lib/bootstrap-3.1.1-dist/js/bootstrap',
    app             : '../js/app',
    config          : '../js/config'
},
shim : {
    angular : {
        exports: 'angular'
    },
    jquery : {
        exports: 'jquery'
    },
    uibootstrap : {
        exports: 'uibootstrap'
    },
    bootstrap : {
        exports: 'bootstrap'
    }
},
// To remove urlArgs on production
urlArgs: "v=" +  (new Date()).getTime() * Math.random()
});

require([
'../js/MainCtrl'
]);

every 2nd hit of F5 on the browser with the index.html loaded i receive the error:

"[$injector:nomod] Module 'MainApp' 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.

Any ideas why?

P.S - removing the ng-app="MainApp" tag and bootstrapping the angular manually after the dom is loaded resolves it, but i'm affraid iv'e done something wrong and want to make sure

EDIT - here is my app.js:

define(["angular", "config"], function(angular) {
    return angular.module('MainApp', ['common']);
});

Here is my config.js:

define([
"angular",
"constants/constants",
"values/values",
"filters/filters",
"services/services",
"factories/factories",
"directives/directives",
"providers/providers",
"controllers/controllers"
], function(angular) {  

return angular.module('common', [
    'common.factories',
    'common.services',
    'common.directives',
    'common.providers',
    'common.constants',
    'common.values',
    'common.controllers',
    'common.filters'
]);
});
Urbanleg
  • 6,252
  • 16
  • 76
  • 139

1 Answers1

0

Just check if the immediately parent folder has any space character in the name, as for my case - my folder structure was like.../In Progress/AngularSample/

I had the same issue, and apparently no issue in code, I eventually changed the parentfolder name from "In Progress" to "In-Progress" and it started working correctly!