gpt4 book ai didi

javascript - html页面找不到 Angular

转载 作者:行者123 更新时间:2023-11-28 19:09:02 24 4
gpt4 key购买 nike

我在 html 页面中有下面的代码,运行它,尽管我不断收到错误,指出“Angular 未定义”,我已在头部包含 Angular ,所以我不确定为什么它无法找到它,我也可以直接点击 Angular 的 url。

<!DOCTYPE>
<html ng-app="test">
<head>
<title>
<script src="https://code.angularjs.org/1.2.25/angular.js"></script>
</title>
</head>
<body ng-controller="TestController">

<form name="CopyFile" ng-submit="copy(fileId)">
<input type="text" ng-model="fileId"/>
<input type="submit" value="Copy"/>
</form>

<div>{{ message }}</div>

<div>{{ error }}</div>

<script type="text/javascript">

(function () {

var app = angular.module("test", []);

var testController = function ($scope, $http) {

$scope.copy = function (fileId) {
$http.get("http://localhost/test/copy/prod.aspx/ToProd?fileId=" + fileId)
.then(onComplete, onError);
};

var onComplete = function (response) {
$scope.message = response;
};

var onError = function (reason) {
$scope.error = "File could not be copied " + reason;
};
};

app.controller("TestController", ["$scope", "$http"], testController);

} ());

</script>

</body>
</html>

最佳答案

这可能不是原因,但您不希望将 Angular 包含在标题中。它应该更像是这样的:

<!DOCTYPE>
<html ng-app="test">
<head>
<title>My Page</title>
<script src="https://code.angularjs.org/1.2.25/angular.js"></script>
</head>
.....

关于javascript - html页面找不到 Angular ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31080730/

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