NgModule FAQs

Angular 模块常见问题

Prerequisites:

前提条件:

A basic understanding of the following concepts:

对下列概念有基本的理解:


NgModules help organize an application into cohesive blocks of functionality.

NgModules 可以帮你把应用组织成一些紧密相关的代码块。

This page answers the questions many developers ask about NgModule design and implementation.

这里回答的是开发者常问起的关于 Angular 模块的设计与实现问题。

What classes should I add to the declarations array?

我应该把哪些类加到 declarations 中?

Add declarable classes—components, directives, and pipes—to a declarations list.

可声明的类(组件、指令和管道)添加到 declarations 列表中。

Declare these classes in exactly one module of the application. Declare them in a module if they belong to that particular module.

这些类只能在应用程序的一个并且只有一个模块中声明。 只有当它们从属于某个模块时,才能把在模块中声明它们。


What is a declarable?

什么是可声明的

Declarables are the class types—components, directives, and pipes—that you can add to a module's declarations list. They're the only classes that you can add to declarations.

可声明的就是组件、指令和管道等可以被加到模块的 declarations 列表中的类。它们也是所有能被加到 declarations 中的类。


What classes should I not add to declarations?

哪些类应该加到 declarations 中?

Add only declarable classes to an NgModule's declarations list.

只有可声明的类才能加到模块的 declarations 列表中。

Do not declare the following:

不要声明:

  • A class that's already declared in another module, whether an app module, @NgModule, or third-party module.

    已经在其它模块中声明过的类。无论它来自应用自己的模块(@NgModule)