`application-name/config/environment` 的 `APP` 属性 中缺少属性

Properties missing from `APP` property of `application-name/config/environment`

说这是我的application-name/config/environment

/* jshint node: true */

module.exports = function(environment) {
  var ENV = {
    modulePrefix: 'app-name',
    environment: environment,
    rootURL: '/',
    locationType: 'auto',

    pageTitle: {
      separator: ' - ',
      // we want to append the nested title as suffix
      prepend: false,
      // replace completely replaces the outer title we don't want that
      replace: false,
    },

    EmberENV: {
      FEATURES: {
        // Here you can enable experimental features on an ember canary build
        // e.g. 'with-controller': true
      },
      EXTEND_PROTOTYPES: {
        // Prevent Ember Data from overriding Date.parse.
        Date: false
      }
    },

    APP: {
      // Here you can pass flags/options to your application instance
      // when it is created
    },

    i18n: {
      defaultLocale: 'en',
    },
  };

  if (environment === 'test') {
    // Testem prefers this...
    ENV.locationType = 'none';

    // keep test console output quieter
    ENV.APP.LOG_ACTIVE_GENERATION = false;
    ENV.APP.LOG_VIEW_LOOKUPS = false;

    ENV.APP.rootElement = '#ember-testing';
    ENV.APP.API_HOST = 'http://dev.api.appname.com';
  }
  else if (environment === 'production') {

  }
  else {
    ENV.APP.API_HOST = 'http://dev.api.appname.com';
  }

  return ENV;
};

It's pretty much the default generated one, except there is an API_HOST in the APP sub property in dev & test mode.

在随机模块中说我这样做

import ENV from 'application-name/config/environment';
console.log(ENV.APP.API_HOST); 

我希望记录 .APP.API_HOST 中的值,除非我看到未定义...如果我记录 ENV.APP 这就是我看到的

note the application name has been removed.

但是检查全局对象有效吗?

console.log(ApplicationName.API_HOST);

现在我不想访问全局对象,因为它有点老套。现在是 2017 年,我们现在有了 es 模块...

我试过的

  1. 确保我使用了正确的环境,我们还没有尝试过产品,因为我们没有产品构建...
  2. This specific plugin,结果一样
  3. 我确实在 Ember slack 的帮助频道上问过这个问题,但我在那里并没有取得太大的成功 :/

当 ember-cli 构建您的应用程序时,如果您有一个获取 index.html 并缓存它,每当你更新你的 environment/config.js 时,它都会进入一个新的 index.html

当你的 service worker 缓存你的 index.html 时,可能会阻止你看到更改,这就是我遇到的问题。

我注意到您在 test 环境中添加了值。只需将它们移动到 development 环境即可。