在我的angular4应用程序中使用angular-cli正确使用environment.ts [英] Properly using environment.ts in my angular4 application with angular-cli

查看:151
本文介绍了在我的angular4应用程序中使用angular-cli正确使用environment.ts的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Intellij Ultimate编写我的angular 4应用程序.

I use Intellij Ultimate to code my angular 4 application.

我创建了一个新的Angular 4项目,其中包含environment.tsenvironment.prod.ts,并且环境已在angular-cli.json中正确配置.

I created a new Angular 4 project, it contains environment.ts and environment.prod.ts and the environments are properly configured in angular-cli.json.

如何将其导入代码中?由于实际上在构建它时,我会声明要使用的环境.它是如何工作的?我需要使用Intellij进行编译吗?

how do I import it in my code? Since actually when I build it I state which environment to use. How does it work? Do I need to compile something with Intellij?

当人们实际导入特定的environment.ts文件时,我尝试使用谷歌搜索功能,并找到了许多示例.但这不好,对吧?因为即使我为其他环境构建,它也会使用相同的environment.ts文件.

I tried googling and found many examples when people actually imported a specific environment.ts file. but that's not good, right? Since it will use the same environment.ts file even if I build for a different environment.

我该怎么办?

推荐答案

关于带角度cli的环境文件,这是一篇非常不错的文章: http://tattoocoder.com/angular-cli-using-the-environment-选项/

Here is a really good article on environment files with angular cli: http://tattoocoder.com/angular-cli-using-the-environment-option/

总而言之,您确实导入了environment.ts,但是将根据其所处的环境来导入正确的文件.如本文所述,角度cli将解决这个问题.

In summary, you do imported environment.ts but the correct file will be imported depending on what environment it is. angular cli will take care of that as explained in the article.

这篇关于在我的angular4应用程序中使用angular-cli正确使用environment.ts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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