简体   繁体   English

如何在Angular中获取variables.env变量并将其分配给environment.ts或environment.prod.ts

[英]How to fetch variables.env variables in Angular and assign it to environment.ts or environment.prod.ts

I have build a docker which contains angular 4 application ,other services like superlogn,feedparser and database couchdb. 我已经构建了一个包含angular 4应用程序的docker,其他服务如superlogn,feedparser和数据库couchdb。

Presently in my root folder i have a varibales.env file where all the variables are declared and can be accessed in superlogin and feedparser services 目前在我的根文件夹中,我有一个varibales.env文件,该文件中声明了所有变量,并且可以在superlogin和feedparser服务中对其进行访问

But if we access the varaiables in angular application liks 但是如果我们在角度应用程序中访问变量

dbusername=process.env.username dbusername = process.env。用户名

then the error we getting in angular production is process is undefined? 那么我们在角度生产中得到的错误是过程是不确定的?

unable to access process.env in angular 4 application? 无法在angular 4应用程序中访问process.env?

the Github link for the project is 该项目的Github链接是

https://github.com/janastu/iihs_couch_services/ https://github.com/janastu/iihs_couch_services/

Because Angular don't have access (and should not) to environment variables. 因为Angular不能(也不应该)访问环境变量。 This is very dangerous for your system. 这对您的系统非常危险。

If you want to expose your environments variables, which I don't recommend, you should create a Node application and make endpoints that return your environment variables. 如果您不想公开环境变量(我不建议这样做),则应创建一个Node应用程序,并使端点返回您的环境变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular environment.ts 问题 JSON。 但是 environment.prod.ts - Angular environment.ts problem JSON. However environment.prod.ts 在environment.ts中连接env变量 - Concatenate env variables in environment.ts 如何使服务命令使用 environment.ts 而不是 environment.prod.ts? - How can I make serve command to use environment.ts instead of environment.prod.ts? 如何将模式另存为environment.prod.ts中的ENV变量? - How to save pattern as ENV variable in environment.prod.ts? 如何将.env文件中的变量传递到angular6 environment.ts文件 - How to pass variables in .env file to angular6 environment.ts file Angular6在environment.ts中使用系统环境变量 - Angular6 using system environment variables in environment.ts Angular生产发布包-环境.prod.ts的值在哪里 - Angular production release package - where is environment.prod.ts values 如何在angular应用程序中从资产文件夹而不是environment.ts文件访问环境变量 - How to access environment variables from assets folder instead of environment.ts file in angular application 在environment.prod.ts文件上进行条件 - make condition on environment.prod.ts file 如何在 Angular 应用程序的 environment.prod.ts 中动态配置与后端的连接? - how to Configure connection to backend dynamically in environment.prod.ts of Angular app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM