3
votes

Here are the ember libraries that I used:

ember-cli  : 0.1.7
Ember      : 1.8.1
Ember Data : 1.0.0-beta.12
Handlebars : 1.3.0

My config/environment.js file contains some api keys. According to the link (http://www.ember-cli.com/#Environments) I can access the variables from environment file with the paths ../config/environment or your-application-name/config/environment.

Now, I need a url from the environment file in a controller and I have the following code:

import Ember from "ember";
import BaseController from 'appkit/controllers/base-controller';
import config from '../config/environment';

var NavigationController = BaseController.extend({
    homeUrl: config.URL
});
export default NavigationController;

When checking the browser I have the following error:

Error: Could not find module appkit/controllers/config/environment

I changed the import path from the controller with 'appkit/config/environment' (according with the above link) and I get the same error message. The problem is that the config/environment.js file is not in the appkit/controllers folder but on the same level with the appkit folder.

My question is: what is the path for importing the config/environment from a controller?

3

3 Answers

5
votes

According to the guide: https://guides.emberjs.com/v2.0.0/configuring-ember/configuring-your-app/

You can access these environment variables in your application code by importing from your-application-name/config/environment.

2
votes

The key is that the error notes that it is looking for the config directory in appkit/controllers/ which is one directory too deep. Due to how your NavigationController is presumably nested, you'll need an import statement like this:

import config from '../../config/environment';

1
votes

Since I cannot find a solution to use variables from the configuration file, I moved the configuration variables in a json object in the index.html file that is generated from my .NET application and I solved the problem.