简体   繁体   English

Angular / Typescript中的导出*(星号)是什么意思

[英]What does export * (asterisk) mean in Angular/Typescript

I was going through a component communication example in Angular then I saw this: 我正在查看Angular中的组件通信示例 ,然后看到了以下内容:

export * from './message.service';

What is the role of this export action and why is it done in another file that is not message.service? 此导出操作的作用是什么?为什么要在另一个不是message.service的文件中完成导出操作? (Yet in the message.service.ts there is an export function which exports the service class) (但在message.service.ts中,有一个导出功能可以导出服务类)

export class MessageService {...

This re-export all the content from the './message.service' . 这将重新导出'./message.service'所有内容。 This is usally done do package multiple modules into a single container module that can more easily be imported by clients. 通常这样做是将多个模块打包到一个容器模块中,客户端可以更轻松地将其导入。 This feature is also called Module Redirects in the documentation. 该功能在文档中也称为Module Redirects

Read here or the docs here 在这里阅读或在这里的文档

For example, you can create index.ts which will reexport all things from a certain directory which have a lot of files which every one of them exports something. 例如,您可以创建index.ts重新导出从中有很多文件的其中他们每个人的东西导出某个目录的所有东西。 Then you can simply import from that one file. 然后,您可以简单地从该文件中导入。

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

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