这是两个文件:
/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中加载。有什么问题?
最佳答案
如评论中所述,您需要调用构造函数(function(){})()
(function() {
'use strict';
angular
.module('login',[]);
})();
关于javascript - 没有依赖项的Angularjs注入(inject)器错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27568456/