How to import modules in Ember-cli


#1

Hi,

I’ve got an Ember service that uses some constants (basically a JSON). These constants are defined in the same file (module) as the service itself. The thing is, that these constants are used all over the project and I would like to import them separately - without the need to import the service, too.

Here is my service file:

 import Ember from 'ember';
 
 export const MY_CONSTANTS = {   
   'CONST_1': 'hello1',
   'CONST_2': 'hello2',
 };
  
 export default Ember.Service.extend({ 
    //some code here 
 });

I would like to achieve something like this:

  //some other module

  import MY_CONSTANTS from '/path/to/file/above';

  export default Ember.Controller.extend({
    doIt: function(){
        console.log(MY_CONSTANTS.CONST_1); //prints hello1
    }.on('init');
  });

I guess this syntax should be possible with ES6, but it is not working for me. Could you please help me?

Thanks

Igor


#3

nevermind… all I had to do is change this:

import MY_CONSTANTS from '/path/to/file/above';

to this:

import {MY_CONSTANTS} from '/path/to/file/above';