2014-07-15 34 views
1

我正在尝试使用requireJS创建一个新的角度项目。AngularJS和RequireJS - 未捕获错误:无模块:MyApp

这里是我的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> 

这里是我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' 
]); 

F5的在与index.html的浏览器每2命中装我收到错误:

"[$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. 

任何想法为什么?

PS - 在DOM加载后手动删除NG-应用=“MainApp”标签和自举角度解决它,但我affraid iv'e做错了什么事,并要确保

编辑 - 这是我的app.js:

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

这里是我的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' 
]); 
}); 
+0

你有没有名为'common'的模块? –

回答

0

只是检查是否立即父文件夹的名称中的任何空格字符,因为我的情况 - 我文件夹结构就像... /进展/ AngularSample/

我有同样的问题,显然没有代码问题,我最终将父文件夹名称从“进行中”更改为“正在进行”,并开始正常工作!

相关问题