1

I would like to define a global config value that I can reference in my Ember.js templates. The value is our support email address. Is there a way to add this to the environment config so that I can reference it in a template?

Andrew
  • 227,796
  • 193
  • 515
  • 708

1 Answers1

2

You can use /config/environment.js to store global config properties. You can access these values from js files such as:

 import Config from '/<app-name>/config/environment';

 export default Ember.Component.extend({
     myProperty: Ember.computed(function(){
         return Config.myProperty;
     }),

     ....
 });

You can use this property in your component's template.

You can also write a helper that access this property from config and supply the value to your templates.

Read more from Ember Guide

ykaragol
  • 6,139
  • 3
  • 29
  • 56
  • So there's no way to access the config values without writing a custom helper? – Andrew Apr 16 '16 at 18:46
  • There is another way: [Look at that answer](http://stackoverflow.com/a/28903727/4545506). Also the other answer on that question is writing a *helper* – ykaragol Apr 16 '16 at 18:49
  • I would recommend to import the config in your `controller` or `component` as in this answer and then place it on a property and use that in your template. – Lux Apr 16 '16 at 21:39
  • I seem to be having trouble importing the config. I've tried several variations of `import ENV from '/frontend/config/environment.js';` and still see the error: Could not find module `frontend/config/environment.js` imported from `frontend/controllers/account`. Any idea what I'm doing wrong? – Andrew Apr 20 '16 at 22:46