Javascript 在使用Yeoman';s角全堆栈发生器?
我用的是约曼的发电机 我想访问前端控制器中的一些环境变量(Javascript 在使用Yeoman';s角全堆栈发生器?,javascript,angularjs,environment-variables,yeoman,Javascript,Angularjs,Environment Variables,Yeoman,我用的是约曼的发电机 我想访问前端控制器中的一些环境变量(main.controller.js)。我知道如何设置环境变量的唯一方法是: server/config/environment/local.env.js 'use strict'; // Use local.env.js for environment variables that grunt will set when the server starts locally. // Use for your api keys, secr
main.controller.js
)。我知道如何设置环境变量的唯一方法是:
server/config/environment/local.env.js
'use strict';
// Use local.env.js for environment variables that grunt will set when the server starts locally.
// Use for your api keys, secrets, etc. This file should not be tracked by git.
//
// You will need to set these on the server you deploy to.
module.exports = {
DOMAIN: 'hidden',
SESSION_SECRET: "hidden",
// Control debug level for modules using visionmedia/debug
DEBUG: 'hidden',
CALENDAR_ID: 'hidden',
API_KEY: 'hidden'
};
然而,据我所知,这只能使它在服务器上访问,但我希望它在前端。以下内容在我的前端控制器中不起作用:ENV.API_KEY
和process.ENV.API_KEY
我该怎么办?这是服务器端文件,所以,您需要让客户端(浏览器)可以访问此文件,您需要确认此文件位于客户端可以直接访问的公共路径中,就像普通web一样。。您可以使用标记加载此源文件,其他文件也可以依赖它 ,它使用grunt自动生成AngularJSmodule@Adam泽纳,我也面临同样的问题,你是怎么解决的?