以下是两个文件:
/login/index.php:
<!DOCTYPE html>
<html lang="ru" ng-app='login'>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="/css/login.css">
</head>
<body>
<div class="border1"></div>
<div class="border2"></div>
<div class="img"></div>
<div >
<form id="loginForm">
<div class="logo"></div>
<label>
<input type="text" id="login">
<span class="title">
Login
</span>
</label>
<label>
<input type="password">
<span class="title">
Password
</span>
</label>
<input type="submit" value="enter">
</form>
</div>
<script src="/js/libs/angular.js"></script>
<script src="/app/js/_login.js"></script>
</body>
</html>
第二个:
/app/js/_login.js:
(function() {
'use strict';
angular
.module('login',[]);
});
我不知道为什么,但我得到以下错误:
Uncaught Error: [$injector:modulerr] Failed to instantiate module login due to:
Error: [$injector:nomod] Module 'login' 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.
如您所见,我有一个没有依赖关系的空模块。所有文件路径都是正确的,苍蝇是可访问的,我可以看到它们在Dev Tools中加载。问题是什么?
答案 0 :(得分:2)
如评论中所述,您需要调用构造函数(function(){})()
(function() {
'use strict';
angular
.module('login',[]);
})();