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) { 
+0

在此处发布代码 – Sajeetharan

+0

通常,AngularJS中的那种错误是由源代码缩小或uglification引起的。你使用的是webpack,gulp还是Rails? – IzumiSy

+0

@IzumiSy,不,我不是。 :) – cryoheart

的问题是在这里: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文件的顺序,错误将消失。

+0

错误仍然存​​在。我已经完成了你所说的话,我只是没有将修改推向回购协议。 – cryoheart

+0

在这种情况下,我想人们会真的需要*看到*在您的网站上发生的错误,以便他们可以调试和帮助您。 https://*.com/help/mcve –

+0

您可以从我给您的存储库运行该项目。 – cryoheart

我修复了这个问题。原因是加载Google Maps API脚本的src中缺少“v = 3”。由于该项目以前工作正常,我仍然不这样做。