gpt4 book ai didi

javascript - 无法管理 Angular 依赖性

转载 作者:行者123 更新时间:2023-12-02 16:47:03 27 4
gpt4 key购买 nike

我开始学习 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>

application.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 文件时,出现以下错误:

Error: [$injector:nomod] Module 'logged-directives' 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.

(我没有包含登录指令,因为它是相同的,并且不需要理解这个问题,我对登录指令也有同样的问题)

我错过了什么吗?

感谢您的帮助!

最佳答案

请更新您创建指令的行:

app.directive('loggedContent', function(){ // L should be lower case

因为,您在 html 中使用了 login-content :)

关于javascript - 无法管理 Angular 依赖性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27030282/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com