Javascript 简单登录表单错误
我是新来的。我创建了一个简单的登录表单,加载页面时出现错误。我无法理解错误,也不知道如何解决此错误。我的代码如下Javascript 简单登录表单错误,javascript,angularjs,Javascript,Angularjs,我是新来的。我创建了一个简单的登录表单,加载页面时出现错误。我无法理解错误,也不知道如何解决此错误。我的代码如下 <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <!-- The above 2 meta tags *mus
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- The above 2 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<title>Digital World</title>
<!-- Bootstrap core CSS -->
<link href="bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
</head>
<body ng-app="digitalWorld">
<div class="container" ng-controller="loginController">
<form ng-submit="login()">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Email">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<p>{{myTxt}}</p>
</div>
<script>
//var app = angular.module("myLogin", []);
/*app.controller("loginController", function($scope) {
$scope.myTxt = "You have not yet clicked submit";
$scope.myFunc = function () {
$scope.myTxt = "You clicked submit!";
}
});*/
</script>
</body>
</html>
a) 我如何解决这个问题
b) 我无法理解控制台错误。如何调试像这样的问题,有什么工具或东西可以调试吗?
有人能帮我吗?因为我是Angular Js的新手,无法调试:
点击链接:[$injector/modulerr?…][1]
事实上,它说:
“数字世界”模块不可用!您要么拼错了模块名,要么忘记加载它
检查模块名称和声明发生了什么: 基本上,angular找不到模块定义(
digitalWorld
)
此处:nomod
(无模块)%3Fp0%3D
digitalWorld
(模块名称)%0AG
在这之后,您将获得angularjs文档的链接,该链接将引导您找到问题解释()
如何修复:
您应该在html中定义应用程序的名称:
ng-app="digitalWorld"
和js中同名的应用程序(模块):
angular.module("digitalWorld", []); //instead of "myLogin"
备注:您可以多次使用相同的名称定义模块,但第一次应该是,angular.module(“digitalWorld”,[])代码>和所有其他时间角度模块(“数字世界”)代码>-无[]
未来如何预防:
如果出现此类或类似错误,只需检查以下列表:
下面列出了angular模块定义中最常见的错误。试试这个
<body ng-app="digitalWorld" ng-controller="loginController">
<div class="container">
<form ng-submit="login()">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Email">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<p>{{myTxt}}</p>
</div>
<script>
var app = angular.module('digitalWorld', []);
appEnq.controller("loginController", function($scope)
{
$scope.myTxt = "You have not yet clicked submit";
$scope.myFunc = function ()
{
$scope.myTxt = "You clicked submit!";
}
});
</script>
</body>
电子邮件地址
密码
提交
{{myTxt}}
var app=angular.module('digitalWorld',[]);
附录控制器(“登录控制器”,功能($scope)
{
$scope.myTxt=“您尚未单击提交”;
$scope.myFunc=函数()
{
$scope.myTxt=“您单击了提交!”;
}
});
您已经定义了一个(myLogin)ng应用程序,并使用了不同的一个(digitalWorld)用于开发目的,使用angular的非精简版本,在脚本src中更改angular.min.js
Forangular.js
。您的js代码是否有此错误?因为您似乎应该声明var app=angular.module(“digitalWorld”,[])代码>而不是var-app=angular.module(“myLogin”,[])
@D555-错误明确指出angular injector无法找到您在脚本中htmlng app=“digitalWorld”
中使用的digitalWorld
替换var app=angular.module(“myLogin”,[])代码>带有var-app=angular.module(“数字世界”,[])代码>如果您按照错误中的链接进行操作,您将得到一个提示:模块“digitalWorld”不可用。您似乎正在使用ng app=“digitalWorld”
,但您的angular应用程序是myLogin
。我按照您的建议更改了代码,但仍然是相同的错误。@D555干得好,继续!;)@D555,别忘了接受答案;)谢谢
<body ng-app="digitalWorld" ng-controller="loginController">
<div class="container">
<form ng-submit="login()">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" placeholder="Email">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<p>{{myTxt}}</p>
</div>
<script>
var app = angular.module('digitalWorld', []);
appEnq.controller("loginController", function($scope)
{
$scope.myTxt = "You have not yet clicked submit";
$scope.myFunc = function ()
{
$scope.myTxt = "You clicked submit!";
}
});
</script>
</body>