Angular 5 - 读取内部文件夹中的配置文件

时间:2018-03-24 23:22:45

标签: angular httpclient angular5

我按照这种方式执行此操作:

使用HttpClient和这段代码:this.http.get(" url / assets / file.json");

但是,如果我的配置文件位于assets文件夹中,我的信息将打开到网络。

如何在内部文件夹(而非资产)中读取此文件?

1 个答案:

答案 0 :(得分:1)

如果你把你的配置文件和environment.ts一样怎么办?您的配置文件将像其他ts文件一样进行编译。

您只需创建一个打字稿文件并在变量中添加您的配置:

export const myconfig = 'your config here';

并且你不需要为它调用http,只是;

import { myconfig } from 'your_config_file'