Angular 2 difference between core and feature modules

这一生的挚爱 提交于 2019-12-31 09:20:43

问题


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).

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.


回答1:


core

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.

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.

shared

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).



来源:https://stackoverflow.com/questions/39447443/angular-2-difference-between-core-and-feature-modules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!