AngularJS错误:[$ injector:modulerr]不知所云
问题描述:
我正在学习使用Google Maps集成创建MEAN堆栈项目的教程。我没有任何问题完成了项目,因此我停止了这个项目。当我回来检查时,它不再工作。我没有改变任何代码。我甚至从我的存储库中提取了以前的工作提交,但是出现错误
[$injector:modulerr] http://errors.angularjs.org/1.2.25/$injector/modulerr?p0=scotchApp&p1=Error…gleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.25%2Fangular.min.js%3A18%3A387)
仍然存在。我真的不知道出了什么问题,因为这以前工作正常。我希望有人能帮忙。
编辑。这是我的项目的'gservice'服务的一部分。
// Creates the gservice factory.
// This will be the primary means by which we interact with Google Maps
angular.module('gservice', [])
.factory('gservice', function($rootScope, $http) {
答
的问题是在这里:components.html
<!-- Client Scripts -->
<script src="../app/client/routes/script.js"></script>
<script src="../app/client/service/gservice.js"></script>
<script src="../app/client/service/aservice.js"></script>
你scotchApp
模块在script.js
定义为:
var scotchApp = angular.module('scotchApp', ['ngRoute',
'ngCookies',
'controllerStoreDetail', 'controllerStoreCategory',
'controllerStoreQuery', 'controllerUserDetail',
'controllerUserAuthentication', 'geolocation',
'gservice', 'aservice',
'datatables'
]);
它有gservice
依赖,aservice
等,但这些文件在script.js
之后加载。所以,当加载你的模块(script.js
)时,角度无法找到这些服务的定义。您需要确保在script.js
之前加载所有依赖项。
@devqon曾问过这个问题:
Is your js file which declares the gservice module included before the js file which declares the scotchApp module?
要你回答:
@devqon Yes it is. I really find this case weird as it was really working perfectly for weeks until now.
似乎哪个不是如此。
纠正您加载JS文件的顺序,错误将消失。
答
我修复了这个问题。原因是加载Google Maps API脚本的src中缺少“v = 3”。由于该项目以前工作正常,我仍然不这样做。
在此处发布代码 – Sajeetharan
通常,AngularJS中的那种错误是由源代码缩小或uglification引起的。你使用的是webpack,gulp还是Rails? – IzumiSy
@IzumiSy,不,我不是。 :) – cryoheart