Angular 2+具有主导入文件

时间:2018-05-17 08:08:41

标签: angular typescript angular6

我有不同的文件与这样的数据:

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....

我该怎么做?

1 个答案:

答案 0 :(得分:3)

创建一个文件,例如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';
相关问题