引导之前,可以使用自定义的角度服务? [英] Possible to use a custom Angular service before bootstrap?

查看:134
本文介绍了引导之前,可以使用自定义的角度服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个服务:

angular.module('USC').service('TemplateService', function() {});

这是我想用我手动引导我的角度项目之前:

That I would like to use before I manually bootstrap my Angular project:

angular.bootstrap(document, ['USC']);

这可能吗?我知道我可以打电话VAR的服务= angular.bootstrap()获得()。对角提供的服务,但我怎么会调用自定义一个模块初始化之前?

Is this possible? I know I can call var service = angular.bootstrap().get(); for Angular provided services, but how would I call a custom one before the module was initialized?

推荐答案

如果它是确定具有比将被应用程序本身所使用的服务的不同实例,就可以达到你想要的东西是这样的:

If it is OK to have a different instance of the service than the one that will be used by the app itself, you can achieve what you want like this:

angular.injector(['ng', 'yourApp']).get('SomeService').doStuff();

又见这个 短演示 。结果
<子>
正如你可以看到服务重新实例化(使计数器从0开始)的角度应用中使用。

这篇关于引导之前,可以使用自定义的角度服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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