`[$injector:nomod] Module 'google-maps' is not avail

`[$injector:nomod] Module 'google-maps' is not available`

本文关键字:google-maps is avail not Module injector nomod      更新时间:2023-09-26

我使用angular-google-maps来处理angular应用程序中的google地图。为此,我必须将angular-google-maps.js添加到项目中。如果我以以下方式添加脚本,页面工作没有任何错误:

<script type="text/javascript" 
        src="http://www.directiv.es/application/html/js/nlaplante/angular-google-maps/angular-google-maps.js"></script>

但是如果我使用本地复制,它将不起作用,像这样:

<script type="text/javascript" 
        src="js/libs/directiv.es/angular-google-maps.js"></script>

查看firebug,我看到angular-google-maps.js文件被加载了,但是在这种情况下,发生了以下错误:

Uncaught Error: [$injector:modulerr] Failed to instantiate module mapsApp due to:
Error: [$injector:modulerr] Failed to instantiate module google-maps due to:
Error: [$injector:nomod] Module 'google-maps' is not available! You either misspelled the...<omitted>...1) 
在网上搜索了几个小时,我没有找到任何原因或解决方案。也许你有一个想法或提示,如何找到原因?

我找到了解决方案,我想把它写在这里的情况下,有人遇到同样的问题。

在我的例子中,我从github下载了angular-google-maps扩展,在windows上提取压缩文件并复制到我的项目中。结果,一个错误发生:Failed to instantiate module google-maps due to ...而加载"相同"的js文件在http一切工作正常。关键是:这不是同一个文件!

解决方案是从URL链接获取文件并将其存储在本地:

可能在下载或解压缩过程中,zip文件被破坏。也许是性格问题。无论什么。

如果我在浏览器中打开链接http://www.directiv.es/application/html/js/nlaplante/angular-google-maps/angular-google-maps.js,我可以右键单击该文件并在"源代码"编辑器中打开源代码并将该文件保存在磁盘上。

现在我可以将新创建的文件复制到我的项目文件夹中,如该位置:js/libs/directiv.es/angular-google-maps.js,一切正常.....