Angular2:模块和组件的区别 [英] Angular2: Module and Component difference

查看:302
本文介绍了Angular2:模块和组件的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太清楚,为什么Angular2有两个概念?

I don't quite to figure out, why Angular2 have two concepts?

  1. 模块

  1. Module

组件

它们之间有什么区别,它们应该扮演什么角色?

What is the difference between them and which should be the role they would play?

  • 我何时需要创建一个子模块?
  • 我何时需要创建一个子组件?
  • When would i need to create a SubModule?
  • When would i need to create a SubComponent?

推荐答案

模块和组件几乎没有什么共同之处,只是它们是带有装饰器的类,并且提供者可以向其注册.

Module and Component have hardly anything in common, except that they are classes with decorators and providers can registered with them.

组件是应用程序中可见的部分,具有可选的行为(事件处理程序)

A component is a visible part of your application with optional behavior (event handlers)

引入了一些模块来拆分您的应用程序以进行延迟加载.

Modules were introduced to split your application for lazy loading.

  • SubModule 通常是一组服务,组件,指令和管道,它们共同构成了可重用的功能. 通过将一个模块添加到另一个模块的imports: [...]中,其所有内容都可用于导入模块.

  • SubModule is usually a set of services, components, directives, and pipes that build together a reusable feature. By adding a module to imports: [...] of another module, all its content is made available to the importing module.

SubComponent 并不是Angular2中的真正术语.只有组件.根组件是一个特殊的组件.区别在于,根组件是通过引导Angular2应用程序创建的,而其他组件是因为其选择器与另一个组件的视图中的HTML匹配而创建的.

SubComponent is not really a term in Angular2. There are just components. One special component is the root component. The difference is that the root component is created by bootstrapping an Angular2 application, while other components are created because their selector matches HTML in the view of another component.

因此,除了根组件之外,所有组件都是子组件.

Therefor, except of the root component all components are subcomponents.

这篇关于Angular2:模块和组件的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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