gpt4 book ai didi

angularjs - Apache 上的未捕获错误 : [$injector:modulerr] Failed to instantiate module error on Angular. js 应用程序

转载 作者:行者123 更新时间:2023-12-04 06:59:56 25 4
gpt4 key购买 nike

我正在使用 Apache 服务器来托管一个 angular 应用程序。
这是 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.


可能有什么问题?

最佳答案

错误是因为数组中存在重复值。我已添加 track by $indexng-repeat来解决这个问题。

文档 :ng-repeat

修改代码 :

<html>
<head>
<script src="/lib/angular/angular.js"></script>
</head>
<script>
var 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 track by $index">

{{word}}

</div>
</div>

</body>
</html>

关于angularjs - Apache 上的未捕获错误 : [$injector:modulerr] Failed to instantiate module error on Angular. js 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28041214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com