简体   繁体   English

从index.ts导出和导入

[英]Export and import from index.ts

I have been working on angular project and came on this very peculiar problem. 我一直在从事角度项目,并遇到了这个非常特殊的问题。 I have created separate module for layouts,login and dashboard. 我为布局,登录和仪表板创建了单独的模块。 On login i want a very specific layout so i did this 登录时我想要一个非常特定的布局,所以我做到了

import { LoginLayout } from '../layouts/login-layout/login-layout.component'; // this works
import { LoginLayout } from '../layouts'; // this doesn't work

import { 
 loginRoute,
 resetPasswordRoute
} './'; 

const LOGIN_ROUTES = [loginRoute, resetPasswordRoute];

export const loginRoute: Routes = [
 path: '',
 component: LoginLayoutComponent,
 children:  LOGIN_ROUTES
]

and i am exporting login layout from index.ts in layouts as 我正在从布局中的index.ts导出登录layouts

...
export * from './login/login-layout/login-layout.compenent';

I am not able to understand why one works and the other doesn't It doesn't even show any errors 我不明白为什么一个有效,而另一个无效,甚至不显示任何错误

When comparing the folder structure of your import that works with the export in the index.ts file then there is an extra folder ./login/ . 比较index.ts文件中与导出index.ts导入的文件夹结构时,会有一个额外的文件夹./login/ Maybe this is an additional component with different name that you exporting. 也许这是您导出的具有不同名称的附加组件。

import { LoginLayout } from '../layouts/login-layout/login-layout.component'; // this works

index.ts 索引

export * from './login/login-layout/login-layout.compenent';

edit 编辑

This is the folder structure I supposed. 这是我应该假设的文件夹结构。

├──dashboard
├──layouts
│     ├──index.ts
│     └──login
│            └──login-layout
│                    login-layout.component.ts 
└──login
      └──somefile-with-import.ts

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM