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

查看:23
本文介绍了使用 angular-cli 在我的 angular4 应用程序中正确使用 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.

我该怎么办?

推荐答案

这是一篇关于 angular 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,但将根据环境导入正确的文件.angular 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.

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

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