html页面找不到angular

html page can not find angular

本文关键字:angular 找不到 html      更新时间:2023-09-26

我在一个html页面中有下面的代码,正在运行它,尽管我一直收到一个错误,说"angular is not defined"我已经在头部中包含了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>

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

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

您在<title>中给出了<script>

<title>
    <script src="https://code.angularjs.org/1.2.25/angular.js"></script>
</title>

请把它移到外面。