Angular2 - WebStorm 通过 index.ts 导入我的模块

Angular2 - WebStorm import my modules by index.ts

场景

我目前正在开发一个越来越复杂的 Angular2 应用程序。为了解决这个问题,我们将应用分成 Angular 个模块。

问题

当我在另一个 Angular 模块中使用一个模块中的 TypeScript class 时,WebStorm 会自动引用完整的文件位置。每次按 Tab

时我都会得到这个
// main.component.ts
import {class1} from "../otherModule/folder/class1";
import {class2} from "../otherModule/folder/class2";

这是目录结构,每个文件夹都包含一个引用其中文件夹的索引桶。

mainModule/
-main.component.ts
-main.module.ts

otherModule/
-folder/
--index.ts
--class1.ts
--class2.ts
-index.ts
-other.module.ts

理想解

理想情况下,我希望 WebStorm 仅在我按下 Tab 键时自动引用模块名称。这样我就可以在模块中更改 class 的位置,而不必担心依赖引用。

import {class1, class2} from "../otherModule";

这个功能似乎是可行的,因为它与 Angular 核心功能和其他 npm 模块一起使用。

import {Component, OnInit, OnDestroy} from "@angular/core";

非常感谢为我指明正确方向的任何帮助。

来自回答

您需要打开文件 |设置 |编辑|代码风格 | Typescript(导入选项卡) 设置并启用选项 [使用目录导入]

注意: 需要 WebStorm 2017.2 或更高版本