html页面无法找到角度

时间:2015-06-26 19:25:39

标签: javascript angularjs

我在html页面中有以下代码,运行它虽然我一直收到一个错误,指出“角度未定义”我已经在头部包含了角度所以我不确定它为什么找不到它,角度的网址我也能直接点击。

<!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>

2 个答案:

答案 0 :(得分:2)

这可能不是原因,但你不希望你的角度包含在标题内。它应该是更像这样的东西:

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

答案 1 :(得分:1)

您在<script>内提供了<title>

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

请将其从外面移除。