我正在研究用TypeScript 2编写的角度2项目,我目前面临着导入机制的问题 .
我项目的每个子文件夹里面都有一个“index.ts”文件,即导出所述文件夹包含的类 .
所以,在我的“app”目录中,我有
app.component.ts
app.module.ts
app.routes.ts
然后,index.ts文件包含:
export * from './app.component';
export * from './app.module';
export * from './app.routes';
我的问题是我无法从位于同一目录中的文件导入导出的类 .
例如,在我的app.module.ts中,我想导入应用程序组件 . 如果我做 :
import { AppComponent } from './app.component';
一切正常!编译时和运行时没有错误 . 生活很酷,生活很美好 .
但我无法做到以下几点:
import { AppComponent } from '.'; // or './', or even './index'
IDE(Visual Studio)实际上正确地解析了导入(它编译时没有错误) . 我甚至从Intellisence获得自动完成功能......
但是我在运行时遇到这个错误:
Error: Unexpected value 'undefined' imported by the module 'AppModule'
我只是不知道为什么 .
注意:通过从子文件夹中的index.ts导入我没有任何错误(例如,我可以从也有索引的'./core'导入) .
先感谢您 :)