核心和功能模块之间的角度2差异 [英] Angular 2 difference between core and feature modules

查看:87
本文介绍了核心和功能模块之间的角度2差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白核心<之间的区别角色2中的/ a>和功能模块据我所知,有三种推荐的模块类型:核心功能分享

I don't understand the difference between core and feature modules in angular 2. As far as I understand there are three recommended types of modules: core, feature and shared.

如果模块导出一些声明(组件,指令和管道),并且许多模块将导入该模块,则该模块应该是共享模块(在共享目录中)。

If a module exports some declarations (components, directives and pipes) and many modules will import this module, then this module should be a shared module (in shared directory).

如果一个模块表示一些声明(组件,指令和管道),只有根模块将导入该模块,那么这个模块应该是一个核心模块(在核心目录中) )。

If a module expors some declarations (components, directives and pipes) and only the root module will import this module, then this module should be a core module (in core directory).

功能模块是否相同?只有root模块导入它们。在这个示例中,有一个CoreModule和一个名为ContactModule的功能模块。我没有看到它们之间的区别。它们都是在根模块中导入的。

Are feature modules the same? Only root module imports them. In this example there is a CoreModule and a feature module called ContactModule. I don't see the difference between them. Both of them are imported in root module.

推荐答案

核心

核心模块包含全局服务的提供者,并且可以防止从延迟加载的模块加载(如链接中所示),因为这很容易导致延迟加载的模块为全局服务获取​​自己的实例的错误(这是违背意图的。)

The core module contains providers for global services and can be guarded against being loaded from lazy loaded modules (as shown in your link) because this can easily cause bugs where lazy loaded modules get their own instance for global services (which is against the intention).

功能
顾名思义 - 一个功能的一个模块

feature As the name says - one module for one feature


否则,功能模块的主要区别在于其意图。

Otherwise, a feature module is distinguished primarily by its intent.

功能模块提供一组紧密结合的功能,专注于应用程序业务域,用户工作流,工具(表单,http,路由)或相关实用程序的集合。

A feature module delivers a cohesive set of functionality focused on an application business domain, a user workflow, a facility (forms, http, routing), or a collection of related utilities.

共享

这主要是为了方便导出多个模块,以便可以使用它们e在想要全部使用它们的组件中(您可能希望在许多其他模块中一起使用的公共管道,组件和指令)。

This is mostly for convenience where several modules are exported so they can be made available at once in components that want to use them all (common pipes, components, and directives you probably want to use together in many other modules).

这篇关于核心和功能模块之间的角度2差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆