未捕获的错误:[$ injector:modulerr]

时间:2016-10-27 06:39:47

标签: angularjs django

这里是header.html

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>

<!-- Angular Includes -->

<script  type="text/javascript" src="{% static 'js/myHeader.module.js' %}"></script>

<body ng-app="myHeader">
    <div ng-controller="HeaderController">
          <h1>{{message}}</h1>
    </div>
</body>

这是myHeader.module.js

var myHeader = angular.module('myHeader', []);

myHeader.controller('HeaderController' , ['$scope', function($scope){

    $scope.message = "hello";

}])

我正在尝试使用上面的模块文件,但它会抛出错误

Failed to instantiate module myHeader due to:
Error: [$injector:nomod] http://errors.angularjs.org/1.5.6/$injector/nomod?p0=myHe...
    at Error (native)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:6:412
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:25:235
    at b (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:24:282)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:25:20
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:39:374
    at q (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:7:355)
    at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:39:222)
    at db (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:43:246)
    at c (https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js:21:19
  

并且它也无法包含js文件......它说404找不到   虽然它被放在相应的文件夹

可能是什么原因以及如何克服它?

1 个答案:

答案 0 :(得分:1)

原因应该是其他地方。提供的代码有效

&#13;
&#13;
var myHeader = angular.module('myHeader', []);

myHeader.controller('HeaderController' , ['$scope', function($scope){

    $scope.message = "hello";

}])
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myHeader">
    <div ng-controller="HeaderController">
          <h1>{{message}}</h1>
    </div>
</body>
&#13;
&#13;
&#13;

问题肯定与这一行有关

<script  type="text/javascript" src="{% static 'js/myHeader.module.js' %}"></script>

确保src是正确的