注入的依赖成为角服务未定义 [英] Injected Dependencies become undefined in angular service

查看:119
本文介绍了注入的依赖成为角服务未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个角服务:

.service("MyService", ["$q", "myDep1", "myDep2", function ($q, myDep1, myDep2) {
    function aFunction() {
        //Breakpoint 2
    }

    return { //Breakpoint 1
        aFunction: aFunction
    }
}]);

断点1 (其中定义的服务), myDep1 myDep2 定义。当我的控制器调用机能缺失和我打断点2 ,这些依赖关系是不确定的(虽然$ Q仍定义)。

At Breakpoint 1 (where the service is defined), myDep1 and myDep2 are defined. When my controller calls aFunction and I hit Breakpoint 2, these dependencies are undefined (although $q is still defined).

是什么给了?我试了一下更改为工厂但这并没有改变任何东西。

What gives?? I tried changing it to a factory but that did not change anything.

推荐答案

我有一个类似的问题,但有一个.provider

I had a similar problem but with a .provider

在这里尝试<一个我的解决方案href=\"http://stackoverflow.com/questions/36201905/injected-dependency-is-undefined-in-unit-test/36209633#36209633\">Injected关系在单元测试未定义

这篇关于注入的依赖成为角服务未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆