无法实例化模块,即使定义了正确的模块

时间:2018-01-07 13:01:36

标签: angularjs angularjs-directive angularjs-scope

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="../angular/angular-1.6.7/angular.js"/>
    <script src="../angular/angular-1.6.7/angular-route.min.js"/>
    <!--script type="text/javascript" src="../modules/familyTree.js"/>
    <script type="text/javascript" src="../controllers/mainController.js"/ -->
    <script type="text/javascript">
        var test= angular.module("myTest", []);
        test.controller("main", ["$scope",function ($scope) {
            $scope.headline = "Its Started";
        }]);
    </script>
</head>
<body ng-app="myTest">
<div ng-controller="main">
    <h1>{{headline}}</h1>
    {{1+2}}
</div>
</body>
</html>

写这段代码无法弄清楚它是什么问题。

请帮忙,不断收到错误。

提前致谢。

angular.js:116 Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to:
Error: [$injector:nomod] Module 'myApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.6.7/$injector/nomod?p0=myApp
    at file:///D:/src/main/resources/templates/angular/angular-1.6.7/angular.js:116:12
    at file:///D:/src/main/resources/templates/angular/angular-1.6.7/angular.js:2303:17
    at ensure (file:///D:/src/main/resources/templates/angular/angular-1.6.7/angular.js:2224:38)

1 个答案:

答案 0 :(得分:0)

您需要关闭所有引用的脚本标记

更改

 <script src="../angular/angular-1.6.7/angular.js"/>
 <script src="../angular/angular-1.6.7/angular-route.min.js"/>

 <script src="../angular/angular-1.6.7/angular.js"></script>
 <script src="../angular/angular-1.6.7/angular-route.min.js"></script>

<强>样本

 var test= angular.module("myTest", []);
  test.controller("main", ["$scope",function ($scope) {
  $scope.headline = "Its Started";
 }]);
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>    
</head>
<body ng-app="myTest">
<div ng-controller="main">
    <h1>{{headline}}</h1>
    {{1+2}}
</div>
</body>
</html>