存储的应用程序配置设置 [英] Storing application configuration settings

查看:109
本文介绍了存储的应用程序配置设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是存储在AngularJS应用程序配置设置的最佳地点?这可能是一些类似的应用程序的常量,查询等,这些都可以从控制器和服务或工厂使用。我可以创建一个单独的服务,存储和检索这些东西,但我不知道是否有存储和检索的另一个合适的地方。

What is the best place to store application configuration settings in AngularJS? This could be things like application constants, lookups etc. which could be used both from controllers and services or factories. I could create a separate service that stores and retrieves these things but I was wondering if there is another proper place to store and retrieve those.

推荐答案

您可以使用常数( )提供商!

app.constant('myAppConfig', {ver: '1.2.2', bananas: 6, hammocks: 3, bananaHammocks: true});

这是不是一大堆从特里的解决方案不同,但常不改变,使他们在其他供应商之前被应用。此外,该模块可以注入到你的配置功能。

This is not a whole lot different from Terry's solution, but constants don't change so they are applied before the other providers. Also, this module can be injected into your config function.

app.config(function(myAppConfig){
    console.log(myAppConfig.bananaHammocks);
});

有乐趣

这篇关于存储的应用程序配置设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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