我检查了所有类似问题,发现了常见问题(脚本标签没有正确关闭等),我找不到为什么我仍然得到"模块' myApp&# 39;不可用!您要么错误拼写了模块名称,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。"错误。有什么想法吗?
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.js"></script>
</head>
<body>
<form action="functions.php?action=edituser" ng-app="myApp" ng-controller="myCtrl">
<p>User ID: <span id="userID" ng-model="userid"><?php echo $_GET['userid']; ?></span></p>
<label>First Name </label><input id="firstname" name="firstname" ng-model="firstName"><br/><br/>
<label>Last Name </label><input id="lastname" name="lastname" ng-model="lastName"><br/><br/>
<label>E-mail Address </label><input id="email" name="email" ng-model="email"><br/><br/>
<label>Cellphone Number </label><input id="cell" name="cell" ng-model="cell"><br/><br/>
<label>Domain </label><input id="companydomain" name="companydomain" ng-model="companydomain"><br/><br/>
<label>ID Number </label><input id="said" name="said" ng-model="said"><br/><br/>
<label>TFA Method </label><select id="tfamethod" name="tfamethod" ng-model="tfamethod">
<option id="gauth" value="gauth">Google Authenticator</option>
<option id="sms" value="sms">SMS</option>
<option id="email" value="email">E-mail</option>
</select><br/><br/>
<label>Reset Password? </label><input id="passreset" name="passreset" ng-model="passreset" type="checkbox" value="Expire Password?"/><br/><br/>
</form>
<script>
var xmlhttp = new XMLHttpRequest();
var app = angular.module('myApp', []);
xmlhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var response = this.responseText;
var myObj = JSON.parse(response);
app.controller('myCtrl', function ($scope) {
$scope.firstName = myObj.firstname;
$scope.lastName = myObj.lastname;
$scope.email = myObj.email;
$scope.cell = myObj.cell;
$scope.domainname = myObj.domainname;
$scope.tfamethod = myObj.tfamethod;
$scope.said = myObj.said;
});
}
};
xmlhttp.open("GET", "functions.php?action=getuserdata&id=" + {{userid}}, true);
xmlhttp.send();
</script>
</body>
</html>
答案 0 :(得分:0)
您需要浏览Angularjs文档。 enter link description here
在您的html / body标记中添加ng-app="myApp"
。
<html ng-app="myApp">
答案 1 :(得分:0)
似乎@ powerfade917评论了解决我问题的问题。
{{userid}} is not valid Javascript and cannot be used in that area, only the app space
我删除了变量并且工作正常。