在哪里定义角度4中的常见环境变量 [英] Where to define common environment variables in angular 4

查看:66
本文介绍了在哪里定义角度4中的常见环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对angular 4还是陌生的.我有一组对于所有环境(例如dev,staging,prod等)都通用的属性.在哪里可以将这些属性放在angular 4中? 我已经阅读了有关环境的信息,但在那里我必须将相同的属性复制到所有环境文件中. environment.tsenvironment.prod.ts

I am new to angular 4. I have a set of properties that is common for all environments such as dev, staging, prod etc. Where can I place those properties in angular 4?.

I have read about environments but there I have to copy the same properties to all environment files ie. environment.ts, environment.prod.ts etc.

推荐答案

创建一个新的environment.common.ts文件,然后将其导入每个环境文件中.

Create a new environment.common.ts file and then import it inside each of your environments files.

environment.common.ts

environment.common.ts

export const commonEnvironment = {
   property1: "value"
};

environment.ts和environment.prod.ts等...

environment.ts and environment.prod.ts etc...

import { commonEnvironment } from './environment.common';

export const environment = {
  production: false,
  common: commonEnvironment
};

您必须使用common属性才能使用子属性.

You have to use the common property to use your sub properties.

这篇关于在哪里定义角度4中的常见环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆