如何将$ rootScope注入服务? [英] How to inject $rootScope into a service?

查看:63
本文介绍了如何将$ rootScope注入服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 $ rootScope 注入以下代码的工厂定义中(以便可以缩小文件大小):

how to inject a $rootScope into the factory definition for the following code (so the file can be minified):

(function() {
    var signalRService = function($rootScope) {
       // ... 
    };

    var app = angular.module("App");
    app.factory("signalRService", signalRService);
}());

推荐答案

解决方案是通过将服务定义作为数组提供:

The way to go about this is by supplying service definition as an array:

var signalRService = ['$rootScope', function($rootScope) {
   // ... 
}];

参数将被最小化,但是注入器将基于数组中的字符串.

Argument will be minifed, but the injector will be based off the string in the array.

那就是说我建议修改这是否真的可行,因为一般而言,不建议依赖 $ rootScope ,因此直接在服务/工厂中使用任何类型的作用域

That said I'd suggest to revise whether this is really the way to go, as generally speaking relying on $rootScope is inadvisable, and so is using any kind of scopes directly in services/factories.

这篇关于如何将$ rootScope注入服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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