angular - Angular 2+ 有一个主导入文件
问题描述
我有这样的数据不同的文件:
export const config1 = { stuff here }
export const config2 = { other stuff here }
export const config3 = { other stuff here }
然后我导入它们:
import { config1 } from 'some path';
import { config2 } from 'some path';
import { config2 } from 'some path';
我要做的是拥有一个包含所有导入的索引文件,所以我只导入 1?
所以代替上面我只需要做
import { whatever } from 'path'
然后我像这样使用它:
whatever.config1....
我怎样才能做到这一点?
解决方案
创建一个文件,例如configs.ts
并从中导出:
export * from 'some path for config1';
export * from 'some path for config2';
export * from 'some path for config3';
然后你可以从这个文件中导入:
import { config1, config2, config3, whatever_else } from './path/to/configs';
推荐阅读
- windows - 如何将消息从电子发送到另一个进程(其他本机 Windows 应用程序)
- c# - 如果找到完全匹配,则 C# 字符串替换
- c++ - 使用按位赋值操作进行 C++ 类型转换
- vbscript - 在 VBScript 中通过 SendKeys 传递 (–)
- python - ImportError: No module named watson_developer_cloud
- hive - load only few files from a HDFS directory
- android - 允许为包裹禁用 Oreo 自动填充服务
- sql - VBA SQL Query only returns numeric values
- javascript - HTML 5 Video: Playing multiple "clips" with javascript
- python - 为什么我不能通过 python 打开/与文件交互