AngularJS and RequireJS - Uncaught Error: No module: MyApp
AngularJS and RequireJS - Uncaught Error: No module: MyApp
我想用requireJS创建一个新的angular项目。
这里是我的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'
]);
在加载了index.html的浏览器上每按第二次F5,我收到错误:
"[$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.
知道为什么吗?
p。S -删除ng-app="MainApp"标签并在dom加载后手动引导angular解决它,但我担心我做错了什么,想确保
编辑-这是我的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'
]);
});
检查父文件夹名称中是否有空格字符,就我的情况而言-我的文件夹结构像…/进步/AngularSample/
我有同样的问题,显然在代码中没有问题,我最终将parentfolder名称从"in Progress"更改为"in -Progress",它开始正常工作!
相关文章:
- 为什么要对define.md和module.exports进行条件检查,以及条件何时通过
- Module.start()已激发两次
- Javascript GetElementByID has no value
- 谷歌地图API v3:Initial View is Fine,but Gray Box with No Map if
- module.js在运行iron节点时找不到模块
- Javascript window.open()toolbar=no不起作用
- Regex表示10位数字,其中没有't允许所有零、所有单个no和序列号
- `npm install` killed for large package.json, no npm-debug.lo
- ES6to5, ES6 Module Transpiler and Babel
- YES或NO表示对象事件中的分号
- Wordpress AJAX with raw javascript? NO Jquery
- 在jasmine规范中使用module.exports
- 我们可以在一个js文件中有多个module.exports语句吗
- 禁用复选框上的输入框 jquery NO onchange
- no-op if 语句会导致 Google 图表失败
- No puedo comparar una variable con un cadena de tipo String
- 在javascript中访问当前页面的页面标题[no ajax]
- JavaScript 动态更改图像 src 的位置 - NO JQuery
- AngularJS: Uncaught Error: No module: GridCambiable
- AngularJS and RequireJS - Uncaught Error: No module: MyApp