我有很多组件,导入部分看起来很臃肿:
import {comp1} from './components/comp1/comp1';
import {comp2} from './components/comp2/comp2';
....
有没有一种编写通用导入的方法?类似于:
import * from './components/';
我有很多组件,导入部分看起来很臃肿:
import {comp1} from './components/comp1/comp1';
import {comp2} from './components/comp2/comp2';
....
import * from './components/';
*
来导入内容,并使用as
关键字创建一个在组件中使用的变量。例如:import * as jwt from 'angular2-jwt/angular2-jwt';
然后在您的组件中按以下方式引用它:
// ...
console.log(jwt.AuthConfig);
export const a: export const b;
- Davidindex.ts
文件的说明。index.ts
的文件,并将想要的所有内容放入其中。path/component/index.ts
export * from './child component 1/index';
export * from './child component 2/index';
export * from './child component 3/index';
export * from './child component 4/index';
export * from './child component 5/index';
...
some/component/*.component.ts
某些组件/ *.组件.ts
import * from 'path/component/index'
从路径/组件/索引导入*