加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 未捕获错误:[$injector:modulerr]无法在Apache上

发布时间:2020-12-17 07:29:44 所属栏目:安全 来源:网络整理
导读:我正在使用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',
我正在使用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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读