AngularJS:由于服务和模块依赖性而未被捕获的对象

时间:2014-06-15 08:40:27

标签: angularjs dependency-injection angularjs-module

我有一个地图服务'带有' MapService'的模块服务如下:

angular.module('maps-services', [])
.service('MapService', [$log, function($log) {
    this.initMap = function() {
    }
    this.updateMap = function() {   
    }
}]);

I also have a 'maps' module depending on 'maps-services' as below:
angular.module('maps', [
   'maps-services'
]);

当我依赖地图'在另一个模块中,我收到一条未被捕获的对象错误消息:

" [$ injector:nomod]模块' ngLocale'不可用!您要么错误拼写了模块名称,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。 http://errors.angularjs.org/1.3.0-beta.11/ $注射器/ NOMOD P0 = ngLocale"

我不明白发生了什么以及如何调试模块加载以更好地了解问题所在。

你能帮我吗?

问候。

1 个答案:

答案 0 :(得分:1)

80年代编译器'式

此异常消息让我想起了80年代编译器抛出的错误消息。

基本上当Angular抛出时:

  

模块' ngLocale'不可用!

这意味着:

  

你的一个模块没有加载(但不是ngLocale)。

有关详细信息,请参阅thisthis

现在为什么没有你的模块加载,或者它是什么模块,供你解决。在我的情况下,有这个

angular.module( 'treeDemoApp' )

而不是

angular.module( 'treeDemoApp', [] )

足以让Angular抛出这条消息。但是你的代码清楚地有[]

Chrome Bug?

有一些建议(12),这是由于Chrome中的错误造成的。