gpt4 book ai didi

javascript - 为什么我的 Controller 显示 {{message}},像这样而不是实际配置的消息

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

<!DOCTYPE html>
<html>
<head>
<script src="js/angular.js"></script>
<script src="js/Script.js"></script>
</head>
<body ng-app="LoginPage" ng-controller = "LoginPageController">
<form action = "next.html" ng-submit="fun1($event)">
username : <input name = "username" ng-model="un">
<div>{{message1}}</div>
password : <input type = "password" name = "password" ng-model="pw">
<div>{{message2}}</div>
<input type = "submit" value = "login">
</form>
</body>
</html>

我正在尝试使用 AngularJs 实现一个基本的登录页面,但是浏览器不会显示实际范围的消息,而是将标签显示为 {{message}}。

//creating a module
var loginPage = angular.module("LoginPage",[]);

//registering the above controller to the module
loginPage.controller("LoginPageController",function ($scope){
$scope.un = "";
$scope.pw = "";
$scope.message1="";
$scope.message2="";


$scope.fun1 = function(e){;
if($scope.un.length == 0){ //checking for length
$scope.message1 = "enter name"; //message 1
e.preventDefault();
}else{
$scope.message1=""; // message 2
}
if($scope.pw.length == 0){
$scope.message2 = "enter password";
e.preventDefault();
}else{
$scope.message2="";

}
}});

最佳答案

Angular JS 未正确包含在您的代码中。请正确添加。工作版本如下:

我刚刚更改了以下行:

 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

如果您想使用下载版本的 Angular 库,请检查您的路径和文件名。

//creating a module
var loginPage = angular.module("LoginPage",[]);

//registering the above controller to the module
loginPage.controller("LoginPageController",function ($scope){
$scope.un = "";
$scope.pw = "";
$scope.message1="";
$scope.message2="";


$scope.fun1 = function(e){;
if($scope.un.length == 0){ //checking for length
$scope.message1 = "enter name"; //message 1
e.preventDefault();
}else{
$scope.message1=""; // message 2
}
if($scope.pw.length == 0){
$scope.message2 = "enter password";
e.preventDefault();
}else{
$scope.message2="";

}
}});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html>
<head>
</head>
<body ng-app="LoginPage" ng-controller = "LoginPageController">
<form action = "next.html" ng-submit="fun1($event)">
username : <input name = "username" ng-model="un">
<div>{{message1}}</div>
password : <input type = "password" name = "password" ng-model="pw">
<div>{{message2}}</div>
<input type = "submit" value = "login">
</form>
</body>
</html>

关于javascript - 为什么我的 Controller 显示 {{message}},像这样而不是实际配置的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48976209/

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