访问当前应用程序配置的正确方法 [英] Correct way to access current application configuration
本文介绍了访问当前应用程序配置的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我添加了一些配置到 myapp / config / environment
:
if (environment === 'development') {
ENV.APP.AuthURL = 'http://localhost:5000/';
}
现在,要使用某种方法或直接访问 window.Myapp
?
Now, to access this configuration should I use some method or directly accessing window.Myapp
?
推荐答案
您可以通过导入 environment.js
使用以下行:
You can access it by importing environment.js
using the line below:
import config from '../config/environment';
例如,假设您想要在控制器中访问您的配置。这是它的样子:
For example, lets say you want to access your configuration in a controller. This is what it would look like:
import Ember from 'ember';
import config from '../config/environment';
export default Ember.Controller.extend({
foo: config.APP.AuthURL
});
如果需要,您现在可以使用控制器的模板访问它:
If you need to, you can now access it in your controller's template using:
{{foo}}
这篇关于访问当前应用程序配置的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文