angularjs – 未捕获错误:[$injector:modulerr]无法在Apache上的Angular.js应用程序上实例化模块错误

前端之家收集整理的这篇文章主要介绍了angularjs – 未捕获错误:[$injector:modulerr]无法在Apache上的Angular.js应用程序上实例化模块错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用Apache服务器来托管一个角度应用程序.
这是index.html:
<html>
  <head>
    <script src="/lib/angular/angular.js">
  </head>
  <script>
     myapp = angular.module('myapp',[]);

     myapp.controller('indexCtrl',function($scope){

          $scope.words = ['It','is','what','it','is']
     });

  </script>

  <body ng-app="myapp">

      <div ng-controller="indexCtrl">
        <div ng-repeat="word in words">
          {{word}}
        </div>
      </div>

  </body>
</html>

当我从浏览器点击html时,它会显示一个包含此错误的空白页:

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.

可能有什么不对?

错误是由于数组内的重复值.我在ng-repeat中添加了$index索引来解决这个问题.

DOCS:ng-repeat

修改后的代码

<html>
  <head>
    <script src="/lib/angular/angular.js"></script>
  </head>
  <script>
     var myapp = angular.module('myapp','is']
     });

  </script>

  <body ng-app="myapp">

      <div ng-controller="indexCtrl">

          <div ng-repeat="word in words track by $index">

             {{word}}

          </div>
      </div>

  </body>
</html>
原文链接:https://www.f2er.com/angularjs/142169.html

猜你在找的Angularjs相关文章