【发布时间】:2014-11-20 01:36:37
【问题描述】:
我开始学习 Angular,但我在管理依赖项时遇到了麻烦,并且不明白为什么这不起作用。
我的html:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" ng-app="client">
<head>
<meta charset="utf-8" />
<title>Title</title>
<link rel="stylesheet" type="text/css" href="mainstyle.css">
<script type="text/javascript" src="includes/files/angular.js"></script>
<script type="text/javascript" src="includes/files/login/login-directives.js"></script>
<script type="text/javascript" src="includes/files/logged/logged-directives.js"></script>
<script type="text/javascript" src="includes/files/application.js"></script>
</head>
<body ng-controller="ApplicationController as controller">
<logged-content ng-show="controller.isLogged"></logged-content>
<login-content ng-show="!controller.isLogged"></login-content>
</body>
</html>
应用程序.js
(函数() { var app = angular.module('client', ['logged-directives', 'login-directives']);
// Controller which contains informations on the session (connected or not, user informations...)
app.controller('ApplicationController', function($scope){
$scope.isLogged = false; // Contains true if the user is Logged into the software
$scope.currentUser = null;
});
})();
记录的指令:
(function(){
var app = angular.module('logged-directives', []);
app.directive('loggedContent', function(){
return{
restrict : 'E',
templateUrl : 'logged-content.html',
}
});
});
登录指令:
(function(){
var app = angular.module('login-directives', []);
app.directive('loginContent', function(){
return{
restrict : 'E',
templateUrl : "includes/files/login/login-content.html",
controller: function($scope) {
this.validateLogin = function(user) {
alert("user:"+ user.login + " pass : "+user.password);
isLogged = true;
currentUser = user;
};
},
controllerAs: "review"
}
});
})();
当我在 chrome 中打开我的 html 文件时,出现以下错误:
错误:[$injector:nomod] 模块 'logged-directives' 不可用! 您要么拼错了模块名称,要么忘记加载它。如果 注册模块确保将依赖项指定为 第二个参数。
(我没有包含登录指令,因为它是相同的,不需要理解这个问题,我对登录指令也有同样的问题)
我错过了什么吗?
感谢您的帮助!
【问题讨论】:
-
没有名为
loggedDirectives的模块,您将其定义为logged-directives。
标签: javascript html angularjs