我正在使用Apache服务器来托管一个角度应用程序.
这是index.html:
这是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索引来解决这个问题.
原文链接:https://www.f2er.com/angularjs/142169.htmlDOCS: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>