当手动引导启动/初始化接入服务角 [英] Access Angular service when manually bootstrapping / initializing

查看:98
本文介绍了当手动引导启动/初始化接入服务角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能进入工厂服务的方法,的的角已经被自举,类似下面的code?

Is it possible to access to a method of a factory service, before Angular has been bootstrapped, similar to the code below?

我需要做一些AJAX请求的角度,以设置了多个全球应用变量开始之前。我曾希望保留的逻辑,这和/或存储的角度服务中的响应,并返回一个承诺......

I need to make a number of AJAX requests before Angular starts in order to set a number of global application variables. I had hoped to keep the logic for this and/or store the responses inside an Angular service, and return a promise...

<script src="scripts/app.js"></script>
<script src="scripts/factories/app.js"></script>

<script>
    angular.element(document).ready(function() {

        factoryName.startup().then(function() {
            angular.bootstrap(document, ['MyApp']);
        }, function(err) {
            console.log(error fetching bootstrap data);
        }

    });
</script>

有没有办法使用以获得类似的行为的替代方法?

Is there an alternative method to use to get a similar behaviour?

推荐答案

您可以在第一服务电话模块运行块的。在以后的服务调用这些参数,您可以为他们服务了$ HTTP缓存或已明确缓存从第一个呼叫的承诺。

You can make the first service calls in module run blocks. When a later service call is made for those variables, you can either serve them out of $http's cache or have explicitly cached the promise from the first call.

// example
myApp.run(function(MyService) {
  // call your function when Angular starts up
  MyService.init();
});

这篇关于当手动引导启动/初始化接入服务角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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